﻿<%@ WebHandler Language="C#" Class="CMember" %>
using System;
using System.Web;
using com.unionpay.upop.sdk;

/// <summary>
/// 
/// </summary>
public class CMember : MyAjaxBase
{
    /// <summary>
    /// 处理程序请求
    /// </summary>
    /// <param name="context"></param>
    public override void ProcessRequest(HttpContext context)
    {
        //try
        //{
        Init();
        switch (operType)
        {
            case "add":
                Add();
                break;
            case "edit":
                Update();
                break;
            case "del":
                Delete();
                break;
            case "addbankcard":
                addbankcard();
                break;
            case "del_card":
                Delbankcard();
                break;
            case "releaseTogether"://发布合买
                releaseTogether();
                break;
            case "joinTogether"://参与合买,跟单
                joinTogether();
                break;
            case "newarrayByMy":
                newarrayByMy();//自购
                break;
            case "newarrayByTogether":
                newarrayByTogether();//合买
                break;
            case "addLottery":
                addLottery();//在积分商城中购买--自购
                break;

            case "dingzhi":
                dingzhi();
                break;
            case "yfgd": //预付固定
                yfgd();
                break;
            case "yfbfb": //预付百分比
                yfbfb();
                break;
            case "sfgd": //实扣固定
                sfgd();
                break;
            case "sfbfb": //实扣百分比
                sfbfb();
                break;

            case "GetLoginInfo":
                GetLoginInfo(context);
                break;

            case "LotteryQS":
                LotteryQS(context);
                break;
            case "Zhuangtai":
                Zhuangtai(context);
                break;

            default:
                break;
        }
        //}
        //catch
        //{
        //    alertmessage("操作异常");
        //}
    }
    private void dingzhi()
    {
        if (loginUserInfo == null)
        {

            alertmessageAnd("/login.aspx");
            return;
        }
    }
    private void addLottery()//在积分商城中购买--自购
    {
        if (loginUserInfo == null)
        {
            alertmessageAndGo("请先登录！", "/Default.aspx");
            return;
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {
                try
                {
                    Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
                    int type = ReadRequest.RequestInt("type");
                    string lotteryInfo = "";
                    if (type == 1)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden1");
                    }
                    else if (type == 2)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden2");
                    }
                    else if (type == 5)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden3");
                    }
                    else if (type == 3)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden4");
                    }
                    else if (type == 4)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden5");
                    }
                    else if (type == 6)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden6");
                    }
                    else if (type == 7)
                    {
                        lotteryInfo = ReadRequest.RequestString("Hidden7");
                    }
                    Model.LotteryBuyDetail model = new Model.LotteryBuyDetail();
                    model.User_id = int.Parse(loginUserInfo.Id.ToString());
                    model.LotteryType = type;
                    model.LotteryQs = ReadRequest.RequestString("qs");
                    model.LotteryNo = lotteryInfo.Replace(" ", "+").Replace(",", "*");
                    model.LotteryCount = 1;
                    model.LotteryMoney = 2;
                    model.LotteryMultiple = 1;
                    model.IsWin = false;
                    model.WinLevel = -1;
                    model.WinMoney = 0;
                    model.AddTime = DateTime.Now;
                    model.lotteryPlay = "单式";
                    model.Flag = false;
                    model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));
                    decimal userAllCount = userAccout.goldTotal + userAccout.total;
                    if (model.LotteryMoney > userAllCount)
                    //if (model.LotteryMoney > userAccout.total)
                    {
                        alertmessageAndGoback("您的账户余额不足请充值！");
                        return;
                    }
                    else
                    {
                        long createid = BLL.LotteryBuyDetail.Add(model);
                        if (createid > 0)
                        {
                            userAccout.total = userAccout.total - model.LotteryMoney;
                            userAccout.buyLotteryTotal = userAccout.buyLotteryTotal + model.LotteryMoney;
                            userAccout.integralTotal = userAccout.integralTotal + model.LotteryMoney;
                            decimal CodeNum = 0;//本次消耗金币数
                            decimal MoneyNum = 0;//本次花费金钱额数
                            if (model.LotteryMoney > userAccout.goldTotal)//金币不足,将金币全部扣除，剩余部分扣账户余额
                            {
                                decimal plus = model.LotteryMoney - userAccout.goldTotal;//扣除金币后的剩余金额
                                userAccout.goldTotal = 0;
                                userAccout.total = userAccout.total - plus;
                                CodeNum = userAccout.goldTotal;
                                MoneyNum = plus;
                            }
                            else//金币充足，优先扣金币
                            {
                                userAccout.goldTotal = userAccout.goldTotal - model.LotteryMoney;
                                userAccout.total = userAccout.total;
                                CodeNum = model.LotteryMoney;
                                MoneyNum = 0;
                            }
                            if (BLL.UsersAccount.Update(userAccout) > 0)
                            {
                                Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                                Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                                Cost_temp.LotteryChippedid = createid;
                                Cost_temp.GoldCode = CodeNum;
                                Cost_temp.Money = MoneyNum;
                                Cost_temp.AddTime = System.DateTime.Now;
                                Cost_temp.LotteryChipperFrom = 1;
                                BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱

                                this.InsertIngratel(userAccout.user_id, 1, "购买彩票获得" + model.LotteryMoney + "分", model.LotteryMoney);
                                //alertmessageAndGo("投注成功！", "/per_record.aspx?n=1");
                                HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                                return;
                            }
                        }
                        else
                        {
                            alertmessageAndGoback("投注失败！");
                            return;
                        }
                    }
                }
                catch
                {
                    alertmessageAndGoback("数据不正确，请重新输入！");
                    return;
                }

            }
        }
        alertmessageAndGoback("数据不正确，请重新输入！");
        return;
    }
    private void newarrayByMy()//自购
    {
        if (loginUserInfo == null)
        {
            alertmessageAndGo("请先登录！", "/Default.aspx");
            return;
        }
        else
        {
            Model.MembershipGrade grade = BLL.MembershipGrade.GetModel(loginUserInfo.userLevel);
            if (loginUserInfo.Id > 0 && grade != null && grade.ID > 0 && grade.AllowGouCai)
            {
                try
                {
                    Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
                    int type = ReadRequest.RequestInt("type");
                    string lotteryPlay = "";

                    string arr1 = ReadRequest.RequestHtmlEnCode("lotteryStr");
                    if (arr1 == "")
                    {
                        arr1 = ReadRequest.RequestString("qq");
                    }
                    string[] list1 = arr1.Split(',');
                    Model.LotteryBuyDetail model = new Model.LotteryBuyDetail();
                    model.User_id = int.Parse(loginUserInfo.Id.ToString());
                    model.LotteryType = type;
                    model.LotteryQs = ReadRequest.RequestString("qs");
                    int fctype = ReadRequest.RequestInt("fctype");
                    if (type == 3)
                    {
                        model.LotteryNo = arr1;
                        int count = 0;
                        for (int i = 0; i < list1.Length; i++)
                        {
                            string[] strlist = list1[i].Split(',');
                            count += strlist[0].Length * strlist[1].Length * strlist[2].Length;
                        }
                        model.LotteryCount = count;
                    }
                    else if (type == 4)
                    {
                        model.LotteryNo = arr1;
                        int count = 0;
                        for (int i = 0; i < list1.Length; i++)
                        {
                            string[] strlist = list1[i].Split(',');
                            count += strlist[0].Length * strlist[1].Length * strlist[2].Length * strlist[3].Length * strlist[4].Length;
                        }
                        model.LotteryCount = count;
                    }
                    else if (type == 5)
                    {
                        for (int j = 0; j < list1.Length; j++)
                        {

                            int aa = Convert.ToInt32(list1[j].ToString().IndexOf('|'));
                            fctype = Convert.ToInt32(list1[j].ToString().Substring(aa + 1, 1));//获取一级ID下级ID值，如3d下的组三ID
                            string strArr = list1[j].ToString().Substring(0, aa); //投注的号码

                            if (fctype == 1 || fctype == 2 || fctype == 6)
                            {
                                model.LotteryNo = strArr;
                                int count = 0;
                                //for (int i = 0; i < strArr.Length; i++)
                                //{
                                string[] strlist = strArr.Split('*');
                                count = strlist[0].Length * strlist[1].Length * strlist[2].Length;
                                //}
                                model.LotteryCount = count;
                            }
                            else if (fctype == 7)
                            {
                                model.LotteryNo = strArr;
                                int count = 0;
                                //for (int i = 0; i < list1.Length; i++)
                                //{
                                string[] strlist = strArr.Split('*');
                                count = strlist[0].Length + strlist[1].Length + strlist[2].Length - 2;
                                //}
                                model.LotteryCount = count;
                            }
                            else if (fctype == 8)
                            {
                                model.LotteryNo = strArr;
                                int count = 0;
                                //for (int i = 0; i < list1.Length; i++)
                                //{
                                string[] strlist = strArr.Split('*');
                                count += strlist[0].Length * strlist[1].Length + strlist[0].Length * strlist[2].Length + strlist[2].Length * strlist[1].Length - strlist[0].Length - strlist[1].Length - strlist[2].Length + 1;

                                //}
                                model.LotteryCount = count;
                            }
                            else if (fctype == 9)
                            {
                                //model.LotteryNo = returnStr2(strArr.Split(','));
                                //model.LotteryCount = strArr.Split(',').Length;
                                model.LotteryNo = strArr;
                                model.LotteryCount = strArr.Length;
                            }
                            else if (fctype == 5)
                            {
                                if (strArr.IndexOf(',') > 0)
                                {
                                    model.LotteryNo = returnStr2(strArr.Split('*'));
                                    model.LotteryCount = strArr.Split('*').Length;
                                }
                                else
                                {
                                    model.LotteryNo = strArr;
                                    model.LotteryCount = 1;
                                }

                            }
                            else if (fctype == 10)
                            {
                                model.LotteryNo = "拖拉机";
                                model.LotteryCount = list1.Length;
                            }
                            else if (fctype == 11)
                            {
                                model.LotteryNo = "猜三同";
                                model.LotteryCount = list1.Length;
                            }
                            else if (fctype == 3 || fctype == 4)
                            {
                                model.LotteryNo = strArr;
                                model.LotteryCount = 1;
                            }

                            model.LotteryMultiple = ReadRequest.RequestInt("yourMulti");
                            model.LotteryMoney = model.LotteryCount * 2 * model.LotteryMultiple;
                            model.IsWin = false;
                            model.WinLevel = -1;
                            model.WinMoney = 0;
                            model.AddTime = DateTime.Now;
                            model.lotteryPlay = lotteryPlay;
                            model.Flag = false;
                            model.fcType = fctype;
                            model.IsOpen = 1;
                            model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));
                            decimal userAllCount1 = userAccout.goldTotal + userAccout.total;
                            if ((model.LotteryMoney) > userAllCount1)
                            //if ((model.LotteryMoney) > userAccout.total)
                            {
                                alertmessageAndGoback("您的账户余额不足请充值！");
                                return;
                            }
                            else
                            {
                                long createid = BLL.LotteryBuyDetail.Add(model);
                                if (createid > 0)
                                {

                                    userAccout.buyLotteryTotal = userAccout.buyLotteryTotal + model.LotteryMoney;
                                    userAccout.integralTotal = userAccout.integralTotal + model.LotteryMoney;
                                    decimal CodeNum = 0;//本次消耗金币数
                                    decimal MoneyNum = 0;//本次花费金钱额数
                                    if (model.LotteryMoney > userAccout.goldTotal)//金币不足,将金币全部扣除，剩余部分扣账户余额
                                    {
                                        decimal plus = model.LotteryMoney - userAccout.goldTotal;//扣除金币后的剩余金额
                                        userAccout.goldTotal = 0;
                                        userAccout.total = userAccout.total - plus;
                                        CodeNum = userAccout.goldTotal;
                                        MoneyNum = plus;
                                    }
                                    else//金币充足，优先扣金币
                                    {
                                        userAccout.goldTotal = userAccout.goldTotal - model.LotteryMoney;
                                        CodeNum = model.LotteryMoney;
                                        MoneyNum = 0;
                                        userAccout.total = userAccout.total;
                                    }

                                    if (BLL.UsersAccount.Update(userAccout) > 0)
                                    {
                                        Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                                        Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                                        Cost_temp.LotteryChippedid = createid;
                                        Cost_temp.GoldCode = CodeNum;
                                        Cost_temp.Money = MoneyNum;
                                        Cost_temp.AddTime = System.DateTime.Now;
                                        Cost_temp.LotteryChipperFrom = 1;
                                        BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                                        this.InsertIngratel(userAccout.user_id, 1, "购买彩票获得" + model.LotteryMoney + "分", model.LotteryMoney);
                                    }
                                }
                                else
                                {
                                    alertmessageAndGoback("投注失败！");
                                    return;
                                }
                            }

                        }
                        HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                        //alertmessageAndGo("投注成功！", "/per_record.aspx?n=1&StrClear=" + type);
                        return;
                    }
                    else if (type == 6)
                    {
                        model.LotteryNo = arr1;
                        int count = 0;
                        for (int i = 0; i < list1.Length; i++)
                        {
                            string[] strlist = list1[i].Split('*');
                            count += strlist[0].Length * strlist[1].Length * strlist[2].Length * strlist[3].Length * strlist[4].Length * strlist[5].Length * strlist[6].Length;
                        }
                        model.LotteryCount = count;
                    }
                    else if (type == 7)
                    {
                        model.LotteryNo = arr1;
                        long count = 0;
                        for (int i = 0; i < list1.Length; i++)
                        {
                            string[] strlist = list1[i].Split('$');
                            if (strlist.Length > 1)
                            {
                                count += (SSQFS(strlist[1].Split('*').Length) / SSQFS(7 - strlist[0].Split('*').Length) / SSQFS(strlist[1].Split('*').Length - 7 + strlist[0].Split('*').Length));
                            }
                            else
                            {
                                string[] newList = strlist[0].Split('*');
                                count += SSQFS(newList.Length) / SSQFS(7) / SSQFS(newList.Length - 7);
                            }
                        }
                        model.LotteryCount = count;
                    }
                    else if (type == 1)
                    {
                        arr1 = arr1.Replace(" ", "+");
                        string[] ssqlist = arr1.Split(',');
                        model.LotteryNo = arr1;
                        long count = 0;
                        for (int i = 0; i < ssqlist.Length; i++)
                        {
                            string[] strlist = ssqlist[i].Split('+');
                            string[] redD = strlist[0].Split('$');
                            if (redD.Length > 1)
                            {
                                count += (SSQFS(redD[1].Split('*').Length) / SSQFS(6 - redD[0].Split('*').Length) / SSQFS(redD[1].Split('*').Length - 6 + redD[0].Split('*').Length) * strlist[1].Split('*').Length);
                            }
                            else
                            {
                                string[] newList = redD[0].Split('*');
                                count += SSQFS(newList.Length) / SSQFS(6) / SSQFS(newList.Length - 6) * strlist[1].Split('*').Length;
                            }
                        }
                        model.LotteryCount = count;
                    }
                    else if (type == 2)
                    {
                        arr1 = arr1.Replace(" ", "+");
                        string[] ssqlist = arr1.Split(',');
                        model.LotteryNo = arr1;
                        long count = 0;
                        for (int i = 0; i < ssqlist.Length; i++)
                        {
                            string[] strlist = ssqlist[i].Split('+');
                            string[] redD = strlist[0].Split('$');
                            string[] bluedtList = strlist[1].Split('$');
                            if (redD.Length > 1)
                            {
                                if (bluedtList.Length > 1)
                                {
                                    count += (SSQFS(redD[1].Split('*').Length) / SSQFS(5 - redD[0].Split('*').Length) / SSQFS(redD[1].Split('*').Length - 5 + redD[0].Split('*').Length))
                                           * (SSQFS(bluedtList[1].Split('*').Length) / SSQFS(2 - bluedtList[0].Split('*').Length) / SSQFS(bluedtList[1].Split('*').Length - 2 + bluedtList[0].Split('*').Length));
                                }
                                else
                                {
                                    count += (SSQFS(redD[1].Split('*').Length) / SSQFS(5 - redD[0].Split('*').Length) / SSQFS(redD[1].Split('*').Length - 5 + redD[0].Split('*').Length))
                                        * (SSQFS(bluedtList[0].Split('*').Length) / SSQFS(2) / SSQFS(bluedtList[0].Split('*').Length - 2));
                                }
                            }
                            else
                            {
                                string[] redList = redD[0].Split('*');
                                string[] blueList = strlist[1].Split('*');
                                count += SSQFS(redList.Length) / SSQFS(5) / SSQFS(redList.Length - 5) * (SSQFS(blueList.Length) / SSQFS(2) / SSQFS(blueList.Length - 2));
                            }
                        }
                        model.LotteryCount = count;
                    }
                    model.LotteryMultiple = ReadRequest.RequestInt("yourMulti");
                    model.LotteryMoney = model.LotteryCount * 2 * model.LotteryMultiple;
                    model.IsWin = false;
                    model.WinLevel = -1;
                    model.WinMoney = 0;
                    model.AddTime = DateTime.Now;
                    model.lotteryPlay = lotteryPlay;
                    model.Flag = false;
                    model.fcType = fctype;
                    model.IsOpen = 1;
                    model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));

                    decimal userAllCount = userAccout.goldTotal + userAccout.total;
                    if (model.LotteryMoney > userAllCount)
                    //if ((model.LotteryMoney) > userAccout.total)
                    {
                        alertmessageAndGoback("您的账户余额不足请充值！");
                        return;
                    }
                    else
                    {
                        long createid = BLL.LotteryBuyDetail.Add(model);
                        if (createid > 0)
                        {
                            userAccout.total = userAccout.total - model.LotteryMoney;
                            userAccout.buyLotteryTotal = userAccout.buyLotteryTotal + model.LotteryMoney;
                            userAccout.integralTotal = userAccout.integralTotal + model.LotteryMoney;
                            decimal CodeNum = 0;//本次消耗金币数
                            decimal MoneyNum = 0;//本次花费金钱额数
                            if (model.LotteryMoney > userAccout.goldTotal)//金币不足,将金币全部扣除，剩余部分扣账户余额
                            {
                                decimal plus = model.LotteryMoney - userAccout.goldTotal;//扣除金币后的剩余金额
                                userAccout.goldTotal = 0;
                                userAccout.total = userAccout.total - plus;
                                CodeNum = userAccout.goldTotal;
                                MoneyNum = plus;
                            }
                            else//金币充足，优先扣金币
                            {
                                userAccout.goldTotal = userAccout.goldTotal - model.LotteryMoney;
                                CodeNum = model.LotteryMoney;
                                MoneyNum = 0;
                                userAccout.total = userAccout.total;
                            }
                            if (BLL.UsersAccount.Update(userAccout) > 0)
                            {
                                Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                                Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());
                                Cost_temp.LotteryChippedid = createid;
                                Cost_temp.GoldCode = CodeNum;
                                Cost_temp.Money = MoneyNum;
                                Cost_temp.AddTime = System.DateTime.Now;
                                Cost_temp.LotteryChipperFrom = 1;
                                BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱

                                this.InsertIngratel(userAccout.user_id, 1, "购买彩票获得" + model.LotteryMoney + "分", model.LotteryMoney);
                                //alertmessageAndGo("投注成功！", "/per_record.aspx?n=1&StrClear=" + type);
                                HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                                return;
                            }
                        }
                        else
                        {
                            alertmessageAndGoback("投注失败！");
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    alertmessageAndGoback(ex.ToString());
                    //alertmessageAndGoback("数据不正确，请重新输入！");
                    return;
                }

            }
            else
            {

                alertmessageAndGoback("您必须是测试会员才可以投注！");
                return;
            }
        }
        alertmessageAndGoback("数据不正确，请重新输入！");
        return;
    }

    private void newarrayByTogether()//合买
    {
        if (loginUserInfo == null)
        {
            alertmessageAndGo("请先登录！", "/Default.aspx");
            return;
        }
        else
        {
            Model.MembershipGrade grade = BLL.MembershipGrade.GetModel(loginUserInfo.userLevel);
            if (loginUserInfo.Id > 0 && grade != null && grade.ID > 0 && grade.AllowGouCai)
            {
                //try
                //{
                Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
                int type = ReadRequest.RequestInt("type");
                int lotteryPlay = 0;
                string arr1 = ReadRequest.RequestHtmlEnCode("lotteryStr");

                if (arr1 == "")
                {
                    arr1 = ReadRequest.RequestString("qq");
                }
                string[] list1 = arr1.Split(',');
                Model.LotteryChipped model = new Model.LotteryChipped();
                model.UserID = int.Parse(loginUserInfo.Id.ToString());
                model.LotteryType = type;
                model.LotteryOpenTime = ReadRequest.RequestString("qs");
                int fctype = ReadRequest.RequestInt("fctype");
                //----Start------
                int mymoney = ReadRequest.RequestInt("mymoney");
                int mybd = ReadRequest.RequestInt("mybd");
                //----End-------
                if (type == 3)
                {
                    model.LotteryNo = arr1;
                    int count = 0;
                    for (int i = 0; i < list1.Length; i++)
                    {
                        string[] strlist = list1[i].Split(',');
                        count += strlist[0].Length * strlist[1].Length * strlist[2].Length;
                    }
                    model.LotteryCount = count;
                }
                else if (type == 4)
                {
                    model.LotteryNo = arr1;
                    int count = 0;
                    for (int i = 0; i < list1.Length; i++)
                    {
                        string[] strlist = list1[i].Split(',');
                        count += strlist[0].Length * strlist[1].Length * strlist[2].Length * strlist[3].Length * strlist[4].Length;
                    }
                    model.LotteryCount = count;
                }
                else if (type == 5)
                {
                    //-------
                    for (int j = 0; j < list1.Length; j++)
                    {

                        int aa = Convert.ToInt32(list1[j].ToString().IndexOf('|'));
                        fctype = Convert.ToInt32(list1[j].ToString().Substring(aa + 1, 1));//获取一级ID下级ID值，如3d下的组三ID
                        string strArr = list1[j].ToString().Substring(0, aa); //投注的号码

                        if (fctype == 1 || fctype == 2 || fctype == 6)
                        {
                            model.LotteryNo = strArr;
                            int count = 0;
                            //for (int i = 0; i < strArr.Length; i++)
                            //{
                            string[] strlist = strArr.Split('*');
                            count = strlist[0].Length * strlist[1].Length * strlist[2].Length;
                            //}
                            model.LotteryCount = count;
                        }
                        else if (fctype == 7)
                        {
                            model.LotteryNo = strArr;
                            int count = 0;
                            //for (int i = 0; i < list1.Length; i++)
                            //{
                            string[] strlist = strArr.Split('*');
                            count = strlist[0].Length + strlist[1].Length + strlist[2].Length - 2;
                            //}
                            model.LotteryCount = count;
                        }
                        else if (fctype == 8)
                        {
                            model.LotteryNo = strArr;
                            int count = 0;
                            //for (int i = 0; i < list1.Length; i++)
                            //{
                            string[] strlist = strArr.Split('*');
                            count += strlist[0].Length * strlist[1].Length + strlist[0].Length * strlist[2].Length + strlist[2].Length * strlist[1].Length - strlist[0].Length - strlist[1].Length - strlist[2].Length + 1;

                            //}
                            model.LotteryCount = count;
                        }
                        else if (fctype == 9)
                        {
                            //model.LotteryNo = returnStr2(strArr.Split(','));
                            //model.LotteryCount = strArr.Split(',').Length;
                            model.LotteryNo = strArr;
                            model.LotteryCount = strArr.Length;
                        }
                        else if (fctype == 5)
                        {
                            if (strArr.IndexOf(',') > 0)
                            {
                                model.LotteryNo = returnStr2(strArr.Split('*'));
                                model.LotteryCount = strArr.Split('*').Length;
                            }
                            else
                            {
                                model.LotteryNo = strArr;
                                model.LotteryCount = 1;
                            }

                        }
                        else if (fctype == 10)
                        {
                            model.LotteryNo = "拖拉机";
                            model.LotteryCount = list1.Length;
                        }
                        else if (fctype == 11)
                        {
                            model.LotteryNo = "猜三同";
                            model.LotteryCount = list1.Length;
                        }
                        else if (fctype == 3 || fctype == 4)
                        {
                            model.LotteryNo = strArr;
                            model.LotteryCount = 1;
                        }
                        model.LotteryMultiple = ReadRequest.RequestInt("yourMulti");
                        model.LotteryMoney = model.LotteryCount * 2 * model.LotteryMultiple;


                        model.Name = ReadRequest.RequestString("lotteryName");
                        if (model.Name.Equals(""))
                        {
                            alertmessageAndGoback("请输入方案标题？");
                            return;
                        }
                        model.Describe = ReadRequest.RequestString("lotteryxy");
                        if (model.Describe.Equals(""))
                        {
                            alertmessageAndGoback("请输入合买宣言？");
                            return;
                        }
                        model.Commission = ReadRequest.RequestString("selectHid");
                        //if (model.Commission.Equals("0.00"))
                        //{
                        //    alertmessageAndGoback("请选择盈利提成？");
                        //    return;
                        //}

                        if (mymoney < Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05))
                        {
                            mymoney = (int)Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05);
                        }
                        if (mymoney > int.Parse(model.LotteryMoney.ToString()))
                        {
                            mymoney = int.Parse(model.LotteryMoney.ToString());
                        }


                        if (mybd < 0)
                        {
                            mybd = 0;
                        }
                        if (mybd > (int.Parse(model.LotteryMoney.ToString()) - mymoney))
                        {
                            mybd = int.Parse(model.LotteryMoney.ToString()) - mymoney;
                        }
                        model.MySub = mymoney;
                        model.MyGua = mybd;
                        model.LotteryPlay = lotteryPlay;//玩法0单式 1复式 2 "全复式" 3胆拖   
                        model.LotteryWinMoney = 0;//盈利佣金
                        model.LotteryJD = Convert.ToDecimal(mymoney) / Convert.ToDecimal(model.LotteryMoney.ToString()) * 100;
                        model.LotteryYE = int.Parse(model.LotteryMoney.ToString()) - mymoney;
                        model.State = false;

                        model.IsWin = false;
                        model.WinLevel = -1;
                        model.WinMoney = 0;
                        model.AddTime = DateTime.Now;
                        model.Flag = false;
                        model.fcType = fctype;
                        model.IsOpen = ReadRequest.RequestInt("gongkaiHid"); ;
                        model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));
                        decimal userAllCount1 = userAccout.goldTotal + userAccout.total;
                        if ((model.MyGua + model.MySub) > userAllCount1)
                        //if ((model.MyGua + model.MySub) > userAccout.total)
                        {
                            alertmessageAndGoback("您的账户余额不足请充值！");
                            return;
                        }
                        else
                        {
                            long createid = BLL.LotteryChipped.Add(model);
                            if (createid > 0)
                            {
                                userAccout.total = userAccout.total - (model.MyGua + model.MySub);
                                userAccout.buyLotteryTotal = userAccout.buyLotteryTotal + (model.MyGua + model.MySub);
                                userAccout.integralTotal = userAccout.integralTotal + (model.MyGua + model.MySub);

                                decimal CodeNum = 0;//本次消耗金币数
                                decimal MoneyNum = 0;//本次花费金钱额数
                                if ((model.MyGua + model.MySub) > userAccout.goldTotal)//金币不足,将金币全部扣除，剩余部分扣账户余额
                                {
                                    decimal plus = (model.MyGua + model.MySub) - userAccout.goldTotal;//扣除金币后的剩余金额
                                    CodeNum = userAccout.goldTotal;
                                    MoneyNum = plus;
                                    userAccout.goldTotal = 0;
                                    userAccout.total = userAccout.total - plus;

                                }
                                else//金币充足，优先扣金币
                                {
                                    userAccout.goldTotal = userAccout.goldTotal - (model.MyGua + model.MySub);
                                    CodeNum = (model.MyGua + model.MySub);
                                    MoneyNum = 0;
                                }

                                if (BLL.UsersAccount.Update(userAccout) > 0)
                                {
                                    Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                                    Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                                    Cost_temp.LotteryChippedid = createid;
                                    Cost_temp.GoldCode = CodeNum;
                                    Cost_temp.Money = MoneyNum;
                                    Cost_temp.AddTime = System.DateTime.Now;
                                    Cost_temp.LotteryChipperFrom = 1;
                                    BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                                    this.InsertIngratel(userAccout.user_id, 1, "购买彩票获得" + (model.MyGua + model.MySub) + "分", (model.MyGua + model.MySub));
                                    //alertmessageAndGo("投注成功！", "/per_together.aspx?n=5&StrClear=" + type);
                                    HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                                    return;
                                }

                            }
                            else
                            {
                                alertmessageAndGoback("投注失败！");
                                return;
                            }
                        }
                        HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                        //alertmessageAndGo("投注成功！", "/per_together.aspx?n=5&StrClear=" + type);
                        return;
                        //-------
                    }
                }
                else if (type == 6)
                {
                    model.LotteryNo = arr1;
                    int count = 0;
                    for (int i = 0; i < list1.Length; i++)
                    {
                        string[] strlist = list1[i].Split('*');
                        count += strlist[0].Length * strlist[1].Length * strlist[2].Length * strlist[3].Length * strlist[4].Length * strlist[5].Length * strlist[6].Length;
                    }
                    model.LotteryCount = count;
                }
                else if (type == 7)
                {
                    model.LotteryNo = arr1;
                    long count = 0;
                    for (int i = 0; i < list1.Length; i++)
                    {
                        string[] strlist = list1[i].Split('$');
                        if (strlist.Length > 1)
                        {
                            count += (SSQFS(strlist[1].Split('*').Length) / SSQFS(7 - strlist[0].Split('*').Length) / SSQFS(strlist[1].Split('*').Length - 7 + strlist[0].Split('*').Length));
                        }
                        else
                        {
                            string[] newList = strlist[0].Split('*');
                            count += SSQFS(newList.Length) / SSQFS(7) / SSQFS(newList.Length - 7);
                        }
                    }
                    model.LotteryCount = count;
                }
                else if (type == 1)
                {
                    arr1 = arr1.Replace(" ", "+");
                    string[] ssqlist = arr1.Split(',');
                    model.LotteryNo = arr1;
                    long count = 0;
                    for (int i = 0; i < ssqlist.Length; i++)
                    {
                        string[] strlist = ssqlist[i].Split('+');
                        string[] redD = strlist[0].Split('$');
                        if (redD.Length > 1)
                        {
                            count += (SSQFS(redD[1].Split('*').Length) / SSQFS(6 - redD[0].Split('*').Length) / SSQFS(redD[1].Split('*').Length - 6 + redD[0].Split('*').Length) * strlist[1].Split('*').Length);
                        }
                        else
                        {
                            string[] newList = redD[0].Split('*');
                            count += SSQFS(newList.Length) / SSQFS(6) / SSQFS(newList.Length - 6) * strlist[1].Split('*').Length;
                        }
                    }
                    model.LotteryCount = count;
                }
                else if (type == 2)
                {
                    arr1 = arr1.Replace(" ", "+");
                    string[] ssqlist = arr1.Split(',');
                    model.LotteryNo = arr1;
                    long count = 0;
                    for (int i = 0; i < ssqlist.Length; i++)
                    {
                        string[] strlist = ssqlist[i].Split('+');
                        string[] redD = strlist[0].Split('$');
                        string[] bluedtList = strlist[1].Split('$');
                        if (redD.Length > 1)
                        {
                            if (bluedtList.Length > 1)
                            {
                                count += (SSQFS(redD[1].Split('*').Length) / SSQFS(5 - redD[0].Split('*').Length) / SSQFS(redD[1].Split('*').Length - 5 + redD[0].Split('*').Length))
                                       * (SSQFS(bluedtList[1].Split('*').Length) / SSQFS(2 - bluedtList[0].Split('*').Length) / SSQFS(bluedtList[1].Split('*').Length - 2 + bluedtList[0].Split('*').Length));
                            }
                            else
                            {
                                count += (SSQFS(redD[1].Split('*').Length) / SSQFS(5 - redD[0].Split('*').Length) / SSQFS(redD[1].Split('*').Length - 5 + redD[0].Split('*').Length))
                                    * (SSQFS(bluedtList[0].Split('*').Length) / SSQFS(2) / SSQFS(bluedtList[0].Split('*').Length - 2));
                            }
                        }
                        else
                        {
                            string[] redList = redD[0].Split('*');
                            string[] blueList = strlist[1].Split('*');
                            count += SSQFS(redList.Length) / SSQFS(5) / SSQFS(redList.Length - 5) * (SSQFS(blueList.Length) / SSQFS(2) / SSQFS(blueList.Length - 2));
                        }
                    }
                    model.LotteryCount = count;
                }
                model.LotteryMultiple = ReadRequest.RequestInt("yourMulti");
                model.LotteryMoney = model.LotteryCount * 2 * model.LotteryMultiple;


                model.Name = ReadRequest.RequestString("lotteryName");
                if (model.Name.Equals(""))
                {
                    alertmessageAndGoback("请输入方案标题？");
                    return;
                }
                model.Describe = ReadRequest.RequestString("lotteryxy");
                if (model.Describe.Equals(""))
                {
                    alertmessageAndGoback("请输入合买宣言？");
                    return;
                }
                model.Commission = ReadRequest.RequestString("selectHid");
                //if (model.Commission.Equals("0.00"))
                //{
                //    alertmessageAndGoback("请选择盈利提成？");
                //    return;
                //}
                //int mymoney = ReadRequest.RequestInt("mymoney");
                if (mymoney < Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05))
                {
                    mymoney = (int)Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05);
                }
                if (mymoney > int.Parse(model.LotteryMoney.ToString()))
                {
                    mymoney = int.Parse(model.LotteryMoney.ToString());
                }

                //int mybd = ReadRequest.RequestInt("mybd");
                if (mybd < 0)
                {
                    mybd = 0;
                }
                if (mybd > (int.Parse(model.LotteryMoney.ToString()) - mymoney))
                {
                    mybd = int.Parse(model.LotteryMoney.ToString()) - mymoney;
                }
                model.MySub = mymoney;
                model.MyGua = mybd;
                model.LotteryPlay = lotteryPlay;//玩法0单式 1复式 2 "全复式" 3胆拖   
                model.LotteryWinMoney = 0;//盈利佣金
                model.LotteryJD = Convert.ToDecimal(mymoney) / Convert.ToDecimal(model.LotteryMoney.ToString()) * 100;
                model.LotteryYE = int.Parse(model.LotteryMoney.ToString()) - mymoney;
                model.State = false;

                model.IsWin = false;
                model.WinLevel = -1;
                model.WinMoney = 0;
                model.AddTime = DateTime.Now;
                model.Flag = false;
                model.fcType = fctype;
                model.IsOpen = ReadRequest.RequestInt("gongkaiHid"); ;
                model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));
                decimal userAllCount = userAccout.goldTotal + userAccout.total;
                if ((model.MyGua + model.MySub) > userAllCount)
                //if ((model.MyGua + model.MySub) > userAccout.total)
                {
                    alertmessageAndGoback("您的账户余额不足请充值！");
                    return;
                }
                else
                {
                    long createid = BLL.LotteryChipped.Add(model);
                    if (createid > 0)
                    {
                        userAccout.total = userAccout.total - (model.MyGua + model.MySub);
                        userAccout.buyLotteryTotal = userAccout.buyLotteryTotal + (model.MyGua + model.MySub);
                        userAccout.integralTotal = userAccout.integralTotal + (model.MyGua + model.MySub);
                        decimal CodeNum = 0;//本次消耗金币数
                        decimal MoneyNum = 0;//本次花费金钱额数
                        if ((model.MyGua + model.MySub) > userAccout.goldTotal)//金币不足,将金币全部扣除，剩余部分扣账户余额
                        {
                            decimal plus = (model.MyGua + model.MySub) - userAccout.goldTotal;//扣除金币后的剩余金额
                            CodeNum = userAccout.goldTotal;
                            MoneyNum = plus;
                            userAccout.goldTotal = 0;
                            userAccout.total = userAccout.total - plus;

                        }
                        else//金币充足，优先扣金币
                        {
                            userAccout.goldTotal = userAccout.goldTotal - (model.MyGua + model.MySub);
                            CodeNum = (model.MyGua + model.MySub);
                            MoneyNum = 0;
                        }
                        if (BLL.UsersAccount.Update(userAccout) > 0)
                        {
                            Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                            Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());
                            Cost_temp.LotteryChippedid = createid;
                            Cost_temp.GoldCode = CodeNum;
                            Cost_temp.Money = MoneyNum;
                            Cost_temp.AddTime = System.DateTime.Now;
                            Cost_temp.LotteryChipperFrom = 1;
                            BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                            this.InsertIngratel(userAccout.user_id, 1, "购买彩票获得" + (model.MyGua + model.MySub) + "分", (model.MyGua + model.MySub));
                            //alertmessageAndGo("投注成功！", "/per_together.aspx?n=5&StrClear=" + type);
                            HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                            return;
                        }
                    }
                    else
                    {
                        alertmessageAndGoback("投注失败！");
                        return;
                    }
                }
                // }
                //catch
                //{
                //    alertmessageAndGoback("数据不正确，请重新输入！");
                //    return;
                //}

            }
            else
            {

                alertmessageAndGoback("您必须是测试会员才可以投注！");
                return;
            }
        }
        alertmessageAndGoback("数据不正确，请重新输入！");
        return;
    }
    private string returnStr(string[] arr)
    {
        string str = "";
        Array.Sort(arr);
        foreach (string array in arr)
        {
            str += array;
        }
        return str;
    }
    private string returnStr2(string[] arr)
    {
        string str = "";
        Array.Sort(arr);
        foreach (string array in arr)
        {
            str += "," + array;
        }
        return str.TrimStart(',');
    }
    //private string returnStr2(string[] arr)
    //{
    //    string str = "";
    //    Array.Sort(arr);
    //    foreach (string array in arr)
    //    {
    //        string aaa = array;
    //        str += "," + array.Substring(0, array.Length - 2);
    //    }
    //    return str.TrimStart(',');
    //}
    private long SSQFS(int n)
    {
        long sum = 1;
        if (n == 0 || n == 1)
        {
            return 1;
        }
        else
        {
            for (int i = 1; i <= n; i++)
            {
                sum *= i;
            }
            return sum;
        }
    }
    private void joinTogether()//参与合买，跟单
    {
        if (loginUserInfo == null)
        {
            returnmessage(false);
            return;
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {
                int toid = ReadRequest.RequestInt("id");
                int tomoney = ReadRequest.RequestInt("tomoney");
                Model.LotteryChipped plan = BLL.LotteryChipped.GetModel(toid);
                Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
                if (plan.UserID != loginUserInfo.Id)//发起人不能跟自己发起的方案
                {
                    if (plan != null && plan.LotteryYE >= tomoney && user_account != null)
                    {
                        decimal allCount = user_account.total + user_account.goldTotal;
                        if (allCount >= tomoney)
                        {
                            plan.LotteryYE = plan.LotteryYE - tomoney;
                            plan.LotteryJD = 100 - ((int)Math.Ceiling((decimal)plan.LotteryYE / (decimal)plan.LotteryMoney * 100));

                            if (plan.LotteryJD >= 100)//进度超过100
                            {
                                plan.LotteryJD = 100;
                                plan.State = true;
                                plan.getalltime = DateTime.Now;
                            }
                            decimal goldCodeNum = 0;
                            decimal moneyNum = 0;
                            if (user_account.goldTotal < tomoney)//金币总额小于购买额，需从账户余额扣
                            {
                                decimal plus = tomoney - user_account.goldTotal;//扣除金币后，需要扣的钱数
                                goldCodeNum = user_account.goldTotal;//本次扣除的金币数
                                moneyNum = plus;//本次在账户中扣除的钱数
                                user_account.goldTotal = 0;
                                user_account.total = user_account.total - plus;

                            }
                            else//金币充足，优先扣金币
                            {
                                user_account.goldTotal = user_account.goldTotal - tomoney;
                                goldCodeNum = tomoney;
                                moneyNum = 0;
                                user_account.total = user_account.total;
                            }
                            //user_account.total = user_account.total - tomoney;
                            user_account.buyLotteryTotal = user_account.buyLotteryTotal + tomoney;
                            user_account.user_id = user_account.user_id;

                            Model.LotteryChippedUser userTz = new Model.LotteryChippedUser();
                            userTz.LotteryChippedId = toid;
                            userTz.UserID = int.Parse(loginUserInfo.Id.ToString());

                            string sqlyhm = "select [nickname] from CMember where Id=" + userTz.UserID;
                            System.Data.DataTable yh = BLL.LotteryChippedUser.GetPageListBysql(sqlyhm);  //根据用户ID 查询当前用户名，进行添加
                            userTz.UserName = Convert.ToString(yh.Rows[0]["nickname"].ToString());
                            userTz.AddTime = DateTime.Now;
                            userTz.MySub = tomoney;
                            userTz.MySubRate = ((decimal)tomoney / (decimal)plan.LotteryMoney).ToString();
                            userTz.IsWin = false;
                            userTz.WinMoney = 0;
                            userTz.Flag = false;
                            userTz.fkfs = 2;//实付扣款2

                            string sqlss = "select count([UserID]) as usercount from [dbo].[LotteryChippedUser] where [LotteryChippedId]= " + ReadRequest.RequestInt("id"); //r如果等于NULL，赋值为O
                            System.Data.DataTable dingzhirsgds = BLL.LotteryChippedUser.GetPageListBysql(sqlss); //查看该订单此时跟单总人数

                            if (Convert.ToInt32(dingzhirsgds.Rows[0]["usercount"].ToString()) >= 1000)//当日跟单总人数不能超过1000人
                            {
                                plan.State = true;
                                BLL.LotteryChipped.Update(plan);

                            }
                            if (BLL.LotteryChippedUser.Add(userTz) > 0)
                            {
                                if (BLL.UsersAccount.Update(user_account) > 0)
                                {
                                    if (BLL.LotteryChipped.Update(plan) > 0)
                                    {

                                        Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                                        Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                                        Cost_temp.LotteryChippedid = plan.id;
                                        Cost_temp.GoldCode = goldCodeNum;
                                        Cost_temp.Money = moneyNum;
                                        Cost_temp.AddTime = System.DateTime.Now;
                                        Cost_temp.LotteryChipperFrom = 1;
                                        BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                                        this.InsertIngratel(user_account.user_id, 1, "购买彩票获得" + tomoney + "分", tomoney);

                                        alertmessageAndGo("购买成功！", "/per_together.aspx");

                                        string sqls = "select count([UserID]) as usercount from [dbo].[LotteryChippedUser] where [LotteryChippedId]= " + ReadRequest.RequestInt("id"); //r如果等于NULL，赋值为O
                                        System.Data.DataTable dingzhirs = BLL.LotteryChippedUser.GetPageListBysql(sqls); //查看该订单此时跟单总人数
                                        if (Convert.ToInt32(dingzhirs.Rows[0]["usercount"].ToString()) >= 1000)
                                        {
                                            plan.State = true;
                                            BLL.LotteryChipped.Update(plan);
                                            hmzt(toid);

                                        }
                                        return;
                                    }
                                }
                            }
                        }
                        else
                        {
                            alertmessageAndGoback("您的可用余额不足！");
                        }
                    }
                }
                else
                {
                    alertmessageAndGoback("您不能购买自己发起的合买！");
                    return;
                }
            }
        }
        alertmessageAndGoback("您不能参与合买，请登录！");
        return;
    }

    private void releaseTogether()
    {
        if (loginUserInfo == null)
        {
            alertmessageAndGoback("请先登录!");
            return;
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {
                try
                {
                    Model.LotteryChipped model = new Model.LotteryChipped();

                    model.UserID = int.Parse(loginUserInfo.Id.ToString());
                    model.LotteryOpenTime = ReadRequest.RequestString("LotteryOpenTime");
                    model.LotteryType = ReadRequest.RequestInt("LotteryType");
                    model.Name = ReadRequest.RequestHtmlEnCode("Name");
                    model.Describe = ReadRequest.RequestString("Describe");
                    model.Commission = ReadRequest.RequestString("Commission");
                    model.MySub = ReadRequest.RequestInt("MySub");
                    model.MyGua = ReadRequest.RequestInt("MyGua");
                    model.LotteryNo = ReadRequest.RequestString("LotteryNo");
                    model.LotteryPlay = ReadRequest.RequestInt("LotteryPlay");
                    model.AddTime = DateTime.Now;
                    model.LotteryCount = 0;
                    model.LotteryMoney = ReadRequest.RequestInt("LotteryMoney");
                    model.LotteryMultiple = ReadRequest.RequestInt("LotteryMultiple");
                    model.LotteryWinMoney = ReadRequest.RequestInt("LotteryWinMoney");
                    model.LotteryJD = 0;
                    model.LotteryYE = 0;
                    model.IsWin = false;
                    model.WinLevel = -1;
                    model.WinMoney = 0;
                    model.Flag = false;
                    model.fcType = 0;//--针对福彩3D 使用 1:直选, 2:通选,3:组三,4:组六,5:和数,6:包选，7:1D，8:2D,9:大小奇偶,10:拖拉机，11:猜三同 
                    model.fcTypeNext = 0;
                    long createid = BLL.LotteryChipped.Add(model);
                    if (createid > 0)
                    {
                        alertmessageAndGo("保存成功，请继续填写！", "/basic.aspx");
                        return;
                    }
                    else
                    {
                        alertmessageAndGoback("数据不正确，请重新输入！");
                        return;
                    }
                }
                catch
                {
                    alertmessageAndGoback("数据不正确，请重新输入！");
                    return;
                }

            }
        }
        alertmessageAndGoback("数据不正确，请重新输入！");
        return;
    }
    decimal Calculate(System.Data.DataRowCollection DR)
    {
        decimal n = 0;
        if (DR.Count != 0)
        {
            for (int i = 0; i < DR.Count; i++)
            {
                n += Convert.ToDecimal(Convert.ToDecimal(DR[i][0]).ToString("0.00"));
            }

        }
        return n;
    }
    void Delbankcard()
    {

        if (loginUserInfo == null)
        {
            returnmessage(false);
            return;
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {
                long cardid = ReadRequest.RequestLong("cardnoid");
                if (cardid > 0)
                {
                    Model.SF_u_Pay upay = BLL.SF_u_Pay.GetModel(cardid);
                    if (upay != null && upay.UserID == loginUserInfo.Id && upay.Id == cardid)
                    {
                        if (BLL.SF_u_Pay.Delete(cardid))
                        {
                            returnmessage(true);
                            return;
                        }
                    }
                }
            }
        }
        returnmessage(false);
        return;
    }
    private void addbankcard()
    {
        if (loginUserInfo != null && loginUserInfo.Id > 0)
        {
            long UserID = loginUserInfo.Id;
            string AccountName = ReadRequest.RequestHtmlEnCode("AccountName");
            string AccountNumber = ReadRequest.RequestHtmlEnCode("AccountNumber");

            if (AccountNumber == null || AccountNumber.Length < 9)
            {
                alertmessageAndGoback("银行卡号不正确，请重新输入！");
                return;
            }
            if (BLL.SF_u_Pay.GetAll_Count(UserID, AccountNumber) > 0)
            {
                alertmessageAndGoback("此卡号已经添加过，请重新输入！");
                return;
            }
            string ckstr = Aboutbank.readurl_checkcardno(AccountNumber);
            if ("0".Equals(ckstr))
            {
                alertmessageAndGoback("银行卡号不正确，请重新输入！");
                return;
            }
            int BankID = ReadRequest.RequestInt("BankName");
            string BranchName = ReadRequest.RequestHtmlEnCode("BranchName");
            decimal realout = Convert.ToDecimal(ReadRequest.RequestHtmlEnCode("r_m_y"));

            Model.SF_u_Pay addbankcard = new Model.SF_u_Pay();
            addbankcard.UserID = UserID;
            addbankcard.AccountName = AccountName;
            addbankcard.AccountNumber = AccountNumber;
            addbankcard.AddTime = DateTime.Now;
            addbankcard.BankID = BankID;
            addbankcard.BankName = Enum.GetName(typeof(Model.RRBEnum.BankID), BankID);
            addbankcard.BranchName = BranchName;
            long bankId = BLL.SF_u_Pay.Add(addbankcard);
            if (bankId > 0)
            {
                tx_user(bankId, realout);
            }
        }
        alertmessageAndGoback("添加银行失败，请重试!");
        return;
    }
    private void tx_user(long bankId, decimal totalm)
    {
        if (loginUserInfo != null)
        {

            Model.UsersAccount user_account = null;
            if (bankId > 0)
            {
                Model.SF_u_Pay u_pay = BLL.SF_u_Pay.GetModel(bankId);
                user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
                if (user_account == null || u_pay == null)
                {
                    alertmessageAndGoback("没有可提现金额!");
                    return;
                }
                if (totalm > user_account.total)
                {
                    alertmessageAndGoback("账户余额不足!");
                    return;
                }
                if (user_account.total - totalm >= 0)
                {
                    user_account.total = user_account.total - totalm;
                    user_account.txTotal = user_account.txTotal + totalm;
                    //user_account.ct_b_money = user_account.ct_b_money + totalm;
                    Model.SF_user_acc_cash tx = new Model.SF_user_acc_cash();
                    tx.s_status = 0;
                    tx.user_id = loginUserInfo.Id;
                    tx.credited = 0;
                    tx.total = totalm;
                    tx.fee = totalm - 0;
                    tx.addtime = DateTime.Now;
                    tx.adduser = loginUserInfo.realname;
                    tx.bankid = u_pay.BankID;
                    tx.branch = u_pay.BranchName;
                    tx.user_mem = u_pay.BankName;
                    tx.account = u_pay.AccountNumber;
                    tx.moduser = u_pay.AccountName;
                    if (BLL.UsersAccount.Update(user_account) > 0)
                    {
                        if (BLL.SF_user_acc_cash.Add(tx) > 0)
                        {
                            alertmessageAndGo("提现操作成功，请等待！", "/withdrawals.aspx?flag=6");
                            return;
                        }
                    }
                }
                else
                {
                    alertmessageAndGoback("账户余额不足!");
                    return;
                }
            }
        }
        alertmessageAndGoback("没有可提现金额!");
        return;
    }
    /// <summary>
    /// 添加
    /// </summary>
    private void Add()
    {
        Model.CMember model = new Model.CMember();
        model.u_password = ReadRequest.RequestHtmlEnCode("txtu_password");
        model.nickname = ReadRequest.RequestHtmlEnCode("txtnickname");
        model.realname = ReadRequest.RequestHtmlEnCode("txtrealname");
        model.cardid = ReadRequest.RequestHtmlEnCode("txtcardid");
        model.mob = ReadRequest.RequestHtmlEnCode("txtmob");
        model.email = ReadRequest.RequestHtmlEnCode("txtemail");
        model.sexnu = ReadRequest.RequestInt("txtsexnu");
        model.cbirth = ReadRequest.RequestHtmlEnCode("txtcbirth");
        model.highestdegree = ReadRequest.RequestHtmlEnCode("txthighestdegree");
        model.entersyear = ReadRequest.RequestInt("txtentersyear");
        model.guniversity = ReadRequest.RequestHtmlEnCode("txtguniversity");
        model.maritalstatus = ReadRequest.RequestHtmlEnCode("txtmaritalstatus");
        model.zaddress = ReadRequest.RequestHtmlEnCode("txtzaddress");
        model.coindustry = ReadRequest.RequestHtmlEnCode("txtcoindustry");
        model.cosize = ReadRequest.RequestHtmlEnCode("txtcosize");
        model.u_position = ReadRequest.RequestHtmlEnCode("txtu_position");
        model.mincome = ReadRequest.RequestHtmlEnCode("txtmincome");
        model.realb = ReadRequest.RequestHtmlEnCode("txtrealb");
        model.realnameb = ReadRequest.RequestHtmlEnCode("ckrealnameb") == "on" ? true : false;
        model.cardidb = ReadRequest.RequestHtmlEnCode("ckcardidb") == "on" ? true : false;
        model.mobb = ReadRequest.RequestHtmlEnCode("ckmobb") == "on" ? true : false;
        model.emailb = ReadRequest.RequestHtmlEnCode("ckemailb") == "on" ? true : false;
        model.qq = ReadRequest.RequestHtmlEnCode("txtqq");
        model.rnd = ReadRequest.RequestHtmlEnCode("txtrnd");
        model.uesrState = ReadRequest.RequestInt("txtuesrState");
        model.registerIP = ReadRequest.RequestHtmlEnCode("txtregisterIP");
        model.cgroup = ReadRequest.RequestInt("txtcgroup");
        model.jg_p = ReadRequest.RequestInt("txtjg_p");
        model.jg_city = ReadRequest.RequestInt("txtjg_city");
        model.hk_p = ReadRequest.RequestInt("txthk_p");
        model.hk_city = ReadRequest.RequestInt("txthk_city");
        model.jz_address = ReadRequest.RequestHtmlEnCode("txtjz_address");
        model.jzb = ReadRequest.RequestHtmlEnCode("ckjzb") == "on" ? true : false;
        model.jzyb = ReadRequest.RequestHtmlEnCode("txtjzyb");
        model.jztel1 = ReadRequest.RequestHtmlEnCode("txtjztel1");
        model.jztel2 = ReadRequest.RequestHtmlEnCode("txtjztel2");

        if (BLL.CMember.Add(model) > 0)
        {
            alertmessage("操作成功");
            return;
        }
        else
        {
            alertmessage("操作失败");
            return;
        }
    }
    /// <summary>
    /// 删除
    /// </summary>
    private void Delete()
    {
        long id = ReadRequest.RequestLong("sid");
        Model.CMember model = BLL.CMember.GetModel(id);
        if (id == 0)
        {
            alertmessage("缺少参数");
        }
        else
        {
            if (BLL.CMember.Delete(id))
            {
                alertmessage("操作成功");
            }
            else
            {
                alertmessage("操作失败");
            }
        }
        return;
    }
    /// <summary>
    /// 批删
    /// </summary>
    private void Drop()
    {
        string ids = ReadRequest.RequestString("dropid");
        if (string.IsNullOrEmpty(ids))
        {
            alertmessage("缺少参数");
        }
        else
        {

            if (BLL.CMember.Drop(ids) > 0)
            {
                alertmessage("操作成功");
            }
            else
            {
                alertmessage("操作失败");
            }
        }
        return;
    }
    /// <summary>
    /// 修改
    /// </summary>
    private void Update()
    {
        Model.CMember model = BLL.CMember.GetModel(ReadRequest.RequestLong("sid"));
        model.u_password = ReadRequest.RequestHtmlEnCode("txtu_password");
        model.nickname = ReadRequest.RequestHtmlEnCode("txtnickname");
        model.realname = ReadRequest.RequestHtmlEnCode("txtrealname");
        model.cardid = ReadRequest.RequestHtmlEnCode("txtcardid");
        model.mob = ReadRequest.RequestHtmlEnCode("txtmob");
        model.email = ReadRequest.RequestHtmlEnCode("txtemail");
        model.sexnu = ReadRequest.RequestInt("txtsexnu");
        model.cbirth = ReadRequest.RequestHtmlEnCode("txtcbirth");
        model.highestdegree = ReadRequest.RequestHtmlEnCode("txthighestdegree");
        model.entersyear = ReadRequest.RequestInt("txtentersyear");
        model.guniversity = ReadRequest.RequestHtmlEnCode("txtguniversity");
        model.maritalstatus = ReadRequest.RequestHtmlEnCode("txtmaritalstatus");
        model.zaddress = ReadRequest.RequestHtmlEnCode("txtzaddress");
        model.coindustry = ReadRequest.RequestHtmlEnCode("txtcoindustry");
        model.cosize = ReadRequest.RequestHtmlEnCode("txtcosize");
        model.u_position = ReadRequest.RequestHtmlEnCode("txtu_position");
        model.mincome = ReadRequest.RequestHtmlEnCode("txtmincome");
        model.realb = ReadRequest.RequestHtmlEnCode("txtrealb");
        model.realnameb = ReadRequest.RequestHtmlEnCode("ckrealnameb") == "on" ? true : false;
        model.cardidb = ReadRequest.RequestHtmlEnCode("ckcardidb") == "on" ? true : false;
        model.mobb = ReadRequest.RequestHtmlEnCode("ckmobb") == "on" ? true : false;
        model.emailb = ReadRequest.RequestHtmlEnCode("ckemailb") == "on" ? true : false;
        model.qq = ReadRequest.RequestHtmlEnCode("txtqq");
        model.rnd = ReadRequest.RequestHtmlEnCode("txtrnd");
        model.uesrState = ReadRequest.RequestInt("txtuesrState");
        model.registerIP = ReadRequest.RequestHtmlEnCode("txtregisterIP");
        model.cgroup = ReadRequest.RequestInt("txtcgroup");
        model.jg_p = ReadRequest.RequestInt("txtjg_p");
        model.jg_city = ReadRequest.RequestInt("txtjg_city");
        model.hk_p = ReadRequest.RequestInt("txthk_p");
        model.hk_city = ReadRequest.RequestInt("txthk_city");
        model.jz_address = ReadRequest.RequestHtmlEnCode("txtjz_address");
        model.jzb = ReadRequest.RequestHtmlEnCode("ckjzb") == "on" ? true : false;
        model.jzyb = ReadRequest.RequestHtmlEnCode("txtjzyb");
        model.jztel1 = ReadRequest.RequestHtmlEnCode("txtjztel1");
        model.jztel2 = ReadRequest.RequestHtmlEnCode("txtjztel2");

        if (BLL.CMember.Update(model) > 0)
        {
            alertmessage("操作成功");
            return;
        }
        else
        {
            alertmessage("操作失败");
            return;
        }
    }



    private void yfgd()//预付固定
    {
        Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
        Model.LotteryChipped modelrs = new Model.LotteryChipped();
        Model.GenDanUser_temp mode2 = new Model.GenDanUser_temp();
        mode2.LotteryChippedid = ReadRequest.RequestInt("fangAnId"); //方案Id
        mode2.user_id = ReadRequest.RequestInt("user_id"); //跟单人ID
        mode2.DJJEmoney = ReadRequest.Requestdecimal("customoney"); //金额
        mode2.Addtime = DateTime.Now; //获取当前时间

        Model.LotteryChippedUser model = new Model.LotteryChippedUser();
        model.LotteryChippedId = ReadRequest.RequestInt("fangAnId"); //方案Id
        model.UserID = ReadRequest.RequestInt("user_id"); //跟单人ID//跟单人ID
        model.MySub = ReadRequest.RequestInt("customoney"); //金额 //金额
        model.AddTime = DateTime.Now;
        model.fkfs = 1; // 付款方式  【1】预付 【2】实扣
        model.fbfb = 1; //付款类型  按【1】固定金额、【2】百分比 
        model.GDCS = ReadRequest.RequestInt("YCCS");

        string sqlyhm = "select [nickname] from CMember where Id=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable yh = BLL.LotteryChippedUser.GetPageListBysql(sqlyhm);  //根据用户ID 查询当前用户名，进行添加
        model.UserName = Convert.ToString(yh.Rows[0]["nickname"].ToString());

        model.MySubRate = Convert.ToString(ReadRequest.Requestdecimal("customoney") / (ReadRequest.Requestdecimal("faje")));//购买比例
        model.IsWin = model.IsWin;
        model.WinMoney = model.WinMoney;
        model.Flag = model.Flag;
        model.Appointtype = model.Appointtype;//该跟单人是否已被指定

        long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));
        Model.LotteryChipped modelye = BLL.LotteryChipped.GetModel(id);
        modelye.id = ReadRequest.RequestInt("fangAnId"); //方案Id
        modelye.UserID = modelye.UserID;
        modelye.AddTime = modelye.AddTime;
        modelye.LotteryOpenTime = modelye.LotteryOpenTime;
        modelye.LotteryType = modelye.LotteryType;
        modelye.Name = modelye.Name;
        modelye.Describe = modelye.Describe;
        modelye.Commission = modelye.Commission;
        modelye.MySub = modelye.MySub;
        modelye.MyGua = modelye.MyGua;
        modelye.LotteryNo = modelye.LotteryNo;
        modelye.LotteryPlay = modelye.LotteryPlay;
        modelye.LotteryCount = modelye.LotteryCount;
        modelye.LotteryMoney = ReadRequest.RequestInt("faje");
        modelye.LotteryMultiple = modelye.LotteryMultiple;
        modelye.LotteryYE = modelye.LotteryYE - Convert.ToInt32(ReadRequest.Requestdecimal("customoney"));
        //实付金额;//方案余额类型数据库中是INT
        modelye.LotteryWinMoney = modelye.LotteryWinMoney;
        modelye.IsWin = modelye.IsWin;
        modelye.WinLevel = modelye.WinLevel;
        modelye.IsOpen = modelye.IsOpen;
        modelye.WinMoney = modelye.WinMoney;
        modelye.State = modelye.State;
        modelye.Flag = modelye.Flag;
        modelye.getalltime = modelye.getalltime;
        modelye.fcType = modelye.fcType;
        modelye.fcTypeNext = modelye.fcTypeNext;
        modelye.secret = modelye.secret;
        modelye.Credit = modelye.Credit;
        modelye.ProjectStatus = 1;  //默认值为1

        // 每个人。一起只能跟一次单。
        string sql = "select * from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId") + " and UserID=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable dingzhi = BLL.LotteryChippedUser.GetPageListBysql(sql);
        if (dingzhi.Rows.Count > 0)
        {
            alertmessageAndGoback("你已经跟过单了");
            return;
        }

        string sqll = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
        System.Data.DataTable dingzhijdye = BLL.LotteryChipped.GetPageListBysql(sqll);

        string sqlst = "select count(UserID) as usercount, isnull(sum(MySub),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
        System.Data.DataTable dingzhirsgd = BLL.LotteryChippedUser.GetPageListBysql(sqlst); //查看当前用户所有跟单金额

        if ((Convert.ToInt32(dingzhirsgd.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdye.Rows[0]["LotteryYE"].ToString()) == 0)))
        {
            Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
            modelzt.State = true;
            BLL.LotteryChipped.Update(modelzt);

        }

        if (BLL.LotteryChippedUser.Add(model) > 0)
        {
            string sqlkgje = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua,MySub from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
            System.Data.DataTable dingzhijd = BLL.LotteryChipped.GetPageListBysql(sqlkgje);

            string sqlstry = "select isnull(sum([MySub]),0) as gendanmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId");//定制人数
            System.Data.DataTable dingzhiGDje = BLL.LotteryChippedUser.GetPageListBysql(sqlstry);
            modelye.LotteryJD = ((Convert.ToDecimal(dingzhijd.Rows[0]["MySub"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje"))) + (Convert.ToDecimal(dingzhiGDje.Rows[0]["gendanmoney"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje")))) * 100;
            if (BLL.GenDanUser_temp.Add(mode2) > 0)
            {
                if (BLL.LotteryChipped.Update(modelye) > 0)
                {
                    alertmessageAnds("定制成功！", "/per_together.aspx?n=5");
                    string sqlsr = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
                    System.Data.DataTable dingzhijdy = BLL.LotteryChipped.GetPageListBysql(sqlsr);

                    string sqlss = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
                    System.Data.DataTable dingzhirsgds = BLL.LotteryChippedUser.GetPageListBysql(sqlss); //查看当前用户所有跟单金额

                    if ((Convert.ToInt32(dingzhirsgds.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdy.Rows[0]["LotteryYE"].ToString()) == 0)))
                    {

                        Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
                        modelzt.State = true;
                        BLL.LotteryChipped.Update(modelzt);
                        fazt(id);
                    }
                    return;
                }


            }

        }


    }

    //跟单人数。如果大于所设定的人数，则更改状态； //跟单人数。如果大于所设定的人数，则更改状态；这里是查找所有跟单人。然后，和已定制人数比较
    //如果人数=定制人数与跟单总金额=方案金额modelrs.State = true; //钱数，人数判断true

    private void yfbfb()//预付百分比
    {

        Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
        Model.LotteryChipped modelrs = new Model.LotteryChipped();
        Model.GenDanUser_temp mode2 = new Model.GenDanUser_temp();
        mode2.LotteryChippedid = ReadRequest.RequestInt("fangAnId"); //方案Id
        mode2.user_id = ReadRequest.RequestInt("user_id"); //跟单人ID
        mode2.DJJEmoney = ReadRequest.Requestdecimal("customoney"); //金额
        mode2.Addtime = DateTime.Now; //获取当前时间

        Model.LotteryChippedUser model = new Model.LotteryChippedUser();
        model.LotteryChippedId = ReadRequest.RequestInt("fangAnId");
        model.UserID = ReadRequest.RequestInt("user_id"); //跟单人ID//跟单人ID
        model.MySub = ReadRequest.RequestInt("customoney"); //金额 //金额
        model.AddTime = DateTime.Now;
        model.fkfs = 1; // 付款方式  【1】预付 【2】实扣
        model.fbfb = 2; //付款类型  按【1】固定金额、【2】百分比 
        model.GDCS = ReadRequest.RequestInt("YFGDCS");

        string sqlyhm = "select [nickname] from CMember where Id=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable yh = BLL.LotteryChippedUser.GetPageListBysql(sqlyhm);  //根据用户ID 查询当前用户名，进行添加
        model.UserName = Convert.ToString(yh.Rows[0]["nickname"].ToString());

        model.MySubRate = ReadRequest.RequestString("YFBL");//购买比例
        model.IsWin = model.IsWin;
        model.WinMoney = model.WinMoney;
        model.Flag = model.Flag;
        model.Appointtype = model.Appointtype;//该跟单人是否已被指定

        long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));
        Model.LotteryChipped modelye = BLL.LotteryChipped.GetModel(id);
        modelye.id = ReadRequest.RequestInt("fangAnId"); //方案Id
        modelye.UserID = modelye.UserID;
        modelye.AddTime = modelye.AddTime;
        modelye.LotteryOpenTime = modelye.LotteryOpenTime;
        modelye.LotteryType = modelye.LotteryType;
        modelye.Name = modelye.Name;
        modelye.Describe = modelye.Describe;
        modelye.Commission = modelye.Commission;
        modelye.MySub = modelye.MySub;
        modelye.MyGua = modelye.MyGua;
        modelye.LotteryNo = modelye.LotteryNo;
        modelye.LotteryPlay = modelye.LotteryPlay;
        modelye.LotteryCount = modelye.LotteryCount;
        modelye.LotteryMoney = modelye.LotteryMoney;
        modelye.LotteryMultiple = modelye.LotteryMultiple;
        modelye.LotteryYE = modelye.LotteryYE - Convert.ToInt32(ReadRequest.Requestdecimal("customoney"));
        //实付金额;//方案余额类型数据库中是INT
        modelye.LotteryWinMoney = modelye.LotteryWinMoney;
        modelye.IsWin = modelye.IsWin;
        modelye.WinLevel = modelye.WinLevel;
        modelye.IsOpen = modelye.IsOpen;
        modelye.WinMoney = modelye.WinMoney;
        modelye.State = modelye.State;
        modelye.Flag = modelye.Flag;
        modelye.getalltime = modelye.getalltime;
        modelye.fcType = modelye.fcType;
        modelye.fcTypeNext = modelye.fcTypeNext;
        modelye.secret = modelye.secret;
        modelye.Credit = modelye.Credit;
        modelye.ProjectStatus = 1;  //默认值为1



        // 每个人。一起只能跟一次单。
        string sql = "select * from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId") + " and UserID=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable dingzhi = BLL.LotteryChippedUser.GetPageListBysql(sql);
        //跟单人数
        if (dingzhi.Rows.Count > 0)
        {
            alertmessageAndGoback("你已经跟过单了");
            return;
        }
        string sqll = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
        System.Data.DataTable dingzhijdye = BLL.LotteryChipped.GetPageListBysql(sqll);

        string sqlst = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
        System.Data.DataTable dingzhirsgd = BLL.LotteryChippedUser.GetPageListBysql(sqlst); //查看当前用户所有跟单金额

        if ((Convert.ToInt32(dingzhirsgd.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdye.Rows[0]["LotteryYE"].ToString()) == 0)))
        {
            Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
            modelzt.State = true;
            BLL.LotteryChipped.Update(modelzt);

        }

        if (BLL.LotteryChippedUser.Add(model) > 0)
        {
            string sqlkgje = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua,MySub from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
            System.Data.DataTable dingzhijd = BLL.LotteryChipped.GetPageListBysql(sqlkgje);
            string sqlstry = "select isnull(sum([MySub]),0) as gendanmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId");//定制人数
            System.Data.DataTable dingzhiGDje = BLL.LotteryChippedUser.GetPageListBysql(sqlstry);
            modelye.LotteryJD = ((Convert.ToDecimal(dingzhijd.Rows[0]["MySub"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje"))) + (Convert.ToDecimal(dingzhiGDje.Rows[0]["gendanmoney"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje")))) * 100;
            if (BLL.GenDanUser_temp.Add(mode2) > 0)
            {
                if (BLL.LotteryChipped.Update(modelye) > 0)
                {
                    alertmessageAnds("定制成功！", "/personal.aspx");
                    string sqlsr = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
                    System.Data.DataTable dingzhijdy = BLL.LotteryChipped.GetPageListBysql(sqlsr);
                    string sqlss = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
                    System.Data.DataTable dingzhirsgds = BLL.LotteryChippedUser.GetPageListBysql(sqlss); //查看当前用户所有跟单金额

                    if ((Convert.ToInt32(dingzhirsgds.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdy.Rows[0]["LotteryYE"].ToString()) == 0)))
                    {
                        Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
                        modelzt.State = true;
                        BLL.LotteryChipped.Update(modelzt);
                        fazt(id);
                    }
                    return;
                }


            }
            else
            {
                alertmessage("操作失败");
                return;
            }
        }

    }



    private void sfgd()//实扣固定
    {
        Model.LotteryChippedUser model = new Model.LotteryChippedUser();
        long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));
        Model.LotteryChipped modelrs = BLL.LotteryChipped.GetModel(id);
        model.LotteryChippedId = ReadRequest.RequestInt("fangAnId"); //方案Id
        model.UserID = ReadRequest.RequestInt("user_id"); //跟单人ID
        model.AddTime = DateTime.Now;
        model.MySub = ReadRequest.RequestInt("customoney"); //金额
        model.fkfs = 2; // 付款方式  【1】预付 【2】实扣
        model.fbfb = 1; //付款类型  按【1】固定金额、【2】百分比 

        string sqlyhm = "select [nickname] from CMember where Id=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable yh = BLL.LotteryChippedUser.GetPageListBysql(sqlyhm);  //根据用户ID 查询当前用户名，进行添加
        model.UserName = Convert.ToString(yh.Rows[0]["nickname"].ToString());
        model.MySubRate = Convert.ToString(ReadRequest.Requestdecimal("customoney") / (ReadRequest.Requestdecimal("faje")));//购买比例
        model.IsWin = model.IsWin;
        model.WinMoney = model.WinMoney;
        model.Flag = model.Flag;
        model.Appointtype = model.Appointtype;//该跟单人是否已被指定

        Model.LotteryChipped modelye = BLL.LotteryChipped.GetModel(id);
        modelye.id = ReadRequest.RequestInt("fangAnId"); //方案Id
        modelye.UserID = modelye.UserID;
        modelye.AddTime = modelye.AddTime;
        modelye.LotteryOpenTime = modelye.LotteryOpenTime;
        modelye.LotteryType = modelye.LotteryType;
        modelye.Name = modelye.Name;
        modelye.Describe = modelye.Describe;
        modelye.Commission = modelye.Commission;
        modelye.MySub = modelye.MySub;
        modelye.MyGua = modelye.MyGua;
        modelye.LotteryNo = modelye.LotteryNo;
        modelye.LotteryPlay = modelye.LotteryPlay;
        modelye.LotteryCount = modelye.LotteryCount;
        modelye.LotteryMoney = modelye.LotteryMoney;
        modelye.LotteryMultiple = modelye.LotteryMultiple;
        modelye.LotteryYE = modelye.LotteryYE - Convert.ToInt32(ReadRequest.Requestdecimal("customoney"));
        //实付金额;//方案余额类型数据库中是INT
        modelye.LotteryWinMoney = modelye.LotteryWinMoney;
        modelye.IsWin = modelye.IsWin;
        modelye.WinLevel = modelye.WinLevel;
        modelye.IsOpen = modelye.IsOpen;
        modelye.WinMoney = modelye.WinMoney;
        modelye.State = modelye.State;
        modelye.Flag = modelye.Flag;
        modelye.getalltime = modelye.getalltime;
        modelye.fcType = modelye.fcType;
        modelye.fcTypeNext = modelye.fcTypeNext;
        modelye.secret = modelye.secret;
        modelye.Credit = modelye.Credit;
        modelye.ProjectStatus = 1; //默认值为1
        //修改总金额，进度，和余额，把其他字段的值回传
        Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
        //user_account.total = user_account.total - ReadRequest.Requestdecimal("customoney"); //实付方案从总金额减去要付的金额

        decimal goldCodeNum = 0;
        decimal MoneyNum = 0;
        if (user_account.goldTotal < ReadRequest.Requestdecimal("customoney"))//账户中金币不足，需要扣一部分钱
        {
            decimal plus = ReadRequest.Requestdecimal("customoney") - user_account.goldTotal;
            goldCodeNum = user_account.goldTotal;
            MoneyNum = plus;
            user_account.goldTotal = 0;
            user_account.total = user_account.total - plus;
        }
        else//金币充足，优先扣金币
        {
            goldCodeNum = ReadRequest.Requestdecimal("customoney");
            MoneyNum = 0;
            user_account.total = user_account.total - ReadRequest.Requestdecimal("customoney");
        }

        //每个人。一起只能跟一次单。
        string sql = "select * from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId") +
                     " and UserID=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable dingzhi = BLL.LotteryChippedUser.GetPageListBysql(sql);
        if (dingzhi.Rows.Count > 0)
        {
            alertmessageAndGoback("你已经跟过单了");
            return;
        } //如果最后定制金额完成之后，把多余的金额退回到当前账户
        string sqll = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
        System.Data.DataTable dingzhijdye = BLL.LotteryChipped.GetPageListBysql(sqll);

        string sqlst = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
        System.Data.DataTable dingzhir = BLL.LotteryChippedUser.GetPageListBysql(sqlst); //查看当前用户所有跟单金额

        if ((Convert.ToInt32(dingzhir.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdye.Rows[0]["LotteryYE"].ToString()) == 0)))
        {
            Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
            modelzt.State = true;
            BLL.LotteryChipped.Update(modelzt);

        }
        if (BLL.LotteryChippedUser.Add(model) > 0)
        {
            string sqlkgje = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua,MySub from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
            System.Data.DataTable dingzhijd = BLL.LotteryChipped.GetPageListBysql(sqlkgje);
            string sqlstry = "select isnull(sum([MySub]),0) as gendanmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId");//定制人数
            System.Data.DataTable dingzhiGDje = BLL.LotteryChippedUser.GetPageListBysql(sqlstry);
            modelye.LotteryJD = ((Convert.ToDecimal(dingzhijd.Rows[0]["MySub"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje"))) + (Convert.ToDecimal(dingzhiGDje.Rows[0]["gendanmoney"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje")))) * 100;

            if (BLL.LotteryChipped.Update(modelye) > 0)
            {
                if (BLL.UsersAccount.Update(user_account) > 0)
                {

                    Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                    Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                    Cost_temp.LotteryChippedid = id;
                    Cost_temp.GoldCode = goldCodeNum;
                    Cost_temp.Money = MoneyNum;
                    Cost_temp.AddTime = System.DateTime.Now;
                    Cost_temp.LotteryChipperFrom = 1;
                    BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                    this.InsertIngratel(user_account.user_id, 1, "购买彩票获得" + ReadRequest.Requestdecimal("customoney") + "分", ReadRequest.Requestdecimal("customoney"));

                    alertmessageAnds("定制成功！", "/per_together.aspx?n=5");

                    string sqlsr = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
                    System.Data.DataTable dingzhijdy = BLL.LotteryChipped.GetPageListBysql(sqlsr);

                    string sqlss = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
                    System.Data.DataTable dingzhirsgd = BLL.LotteryChippedUser.GetPageListBysql(sqlss); //查看当前用户所有跟单金额

                    if ((Convert.ToInt32(dingzhirsgd.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdy.Rows[0]["LotteryYE"].ToString()) == 0)))
                    {
                        Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
                        modelzt.State = true;
                        BLL.LotteryChipped.Update(modelzt);
                        fazt(id);
                    }
                    return;
                }
            }

        }

    }

    private void sfbfb()//实扣百分比
    {
        Model.LotteryChippedUser model = new Model.LotteryChippedUser();
        Model.LotteryChipped modelrs = new Model.LotteryChipped();
        long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));
        model.LotteryChippedId = ReadRequest.RequestInt("fangAnId"); //方案Id
        model.UserID = ReadRequest.RequestInt("user_id"); //跟单人ID//跟单人ID
        model.MySub = ReadRequest.RequestInt("customoney"); //金额 //金额
        model.AddTime = DateTime.Now;
        model.fkfs = 2; // 付款方式  【1】预付 【2】实扣
        model.fbfb = 2; //付款类型  按【1】固定金额、【2】百分比 

        string sqlyhm = "select [nickname] from CMember where Id=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable yh = BLL.LotteryChippedUser.GetPageListBysql(sqlyhm);  //根据用户ID 查询当前用户名，进行添加

        model.UserName = Convert.ToString(yh.Rows[0]["nickname"].ToString());

        model.MySubRate = ReadRequest.RequestString("SFbfb");//购买比例//购买比例(不知道保留多少小数位数，如果，购买2块钱，金额为2万，四舍五入就为0)
        model.IsWin = model.IsWin;
        model.WinMoney = model.WinMoney;
        model.Flag = model.Flag;
        model.Appointtype = model.Appointtype;//该跟单人是否已被指定
        Model.LotteryChipped modelye = BLL.LotteryChipped.GetModel(id);
        modelye.id = ReadRequest.RequestInt("fangAnId"); //方案Id
        modelye.UserID = modelye.UserID;
        modelye.AddTime = modelye.AddTime;
        modelye.LotteryOpenTime = modelye.LotteryOpenTime;
        modelye.LotteryType = modelye.LotteryType;
        modelye.Name = modelye.Name;
        modelye.Describe = modelye.Describe;
        modelye.Commission = modelye.Commission;
        modelye.MySub = modelye.MySub;
        modelye.MyGua = modelye.MyGua;
        modelye.LotteryNo = modelye.LotteryNo;
        modelye.LotteryPlay = modelye.LotteryPlay;
        modelye.LotteryCount = modelye.LotteryCount;
        modelye.LotteryMoney = modelye.LotteryMoney;
        modelye.LotteryMultiple = modelye.LotteryMultiple;
        modelye.LotteryYE = modelye.LotteryYE - Convert.ToInt32(ReadRequest.Requestdecimal("customoney"));
        //实付金额;//方案余额类型数据库中是INT
        modelye.LotteryWinMoney = modelye.LotteryWinMoney;
        modelye.IsWin = modelye.IsWin;
        modelye.WinLevel = modelye.WinLevel;
        modelye.IsOpen = modelye.IsOpen;
        modelye.WinMoney = modelye.WinMoney;
        modelye.State = modelye.State;
        modelye.Flag = modelye.Flag;
        modelye.getalltime = modelye.getalltime;
        modelye.fcType = modelye.fcType;
        modelye.fcTypeNext = modelye.fcTypeNext;
        modelye.secret = modelye.secret;
        modelye.Credit = modelye.Credit;
        modelye.ProjectStatus = 1; //默认值为1

        //修改总金额，进度，和余额，把其他字段的值回传
        Model.UsersAccount user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
        //user_account.total = user_account.total - ReadRequest.Requestdecimal("customoney"); //实付方案从总金额减去要付的金额
        decimal goldCodeNum = 0;
        decimal MoneyNum = 0;
        if (user_account.goldTotal < ReadRequest.Requestdecimal("customoney"))//账户中金币不足，需要扣一部分钱
        {
            decimal plus = ReadRequest.Requestdecimal("customoney") - user_account.goldTotal;
            goldCodeNum = user_account.goldTotal;
            MoneyNum = plus;
            user_account.goldTotal = 0;
            user_account.total = user_account.total - plus;
        }
        else//金币充足，优先扣金币
        {
            goldCodeNum = ReadRequest.Requestdecimal("customoney");
            MoneyNum = 0;
            user_account.total = user_account.total - ReadRequest.Requestdecimal("customoney");
        }
        //每个人。一起只能跟一次单。
        string sql = "select * from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId") +
                     " and UserID=" + ReadRequest.RequestInt("user_id");
        System.Data.DataTable dingzhi = BLL.LotteryChippedUser.GetPageListBysql(sql);
        if (dingzhi.Rows.Count > 0)
        {
            alertmessageAndGoback("你已经跟过单了");
            return;
        } //如果最后定制金额完成之后，把多余的金额退回到当前账户
        string sqll = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua,MySub from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
        System.Data.DataTable dingzhijdye = BLL.LotteryChipped.GetPageListBysql(sqll);

        string sqlst = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
        System.Data.DataTable dingzhirsgd = BLL.LotteryChippedUser.GetPageListBysql(sqlst); //查看当前用户所有跟单金额


        if ((Convert.ToInt32(dingzhirsgd.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdye.Rows[0]["LotteryYE"].ToString()) == 0)))
        {
            Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
            modelzt.State = true;
            BLL.LotteryChipped.Update(modelzt);


        }
        if (BLL.LotteryChippedUser.Add(model) > 0)
        {
            string sqlkgje = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua,MySub from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
            System.Data.DataTable dingzhijd = BLL.LotteryChipped.GetPageListBysql(sqlkgje);
            string sqlstry = "select isnull(sum([MySub]),0) as gendanmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId");//定制人数
            System.Data.DataTable dingzhiGDje = BLL.LotteryChippedUser.GetPageListBysql(sqlstry);
            modelye.LotteryJD = ((Convert.ToDecimal(dingzhijd.Rows[0]["MySub"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje"))) + (Convert.ToDecimal(dingzhiGDje.Rows[0]["gendanmoney"].ToString()) / Convert.ToDecimal(ReadRequest.RequestInt("faje")))) * 100;
            if (BLL.LotteryChipped.Update(modelye) > 0)
            {
                if (BLL.UsersAccount.Update(user_account) > 0)
                {
                    Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                    Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                    Cost_temp.LotteryChippedid = id;
                    Cost_temp.GoldCode = goldCodeNum;
                    Cost_temp.Money = MoneyNum;
                    Cost_temp.AddTime = System.DateTime.Now;
                    Cost_temp.LotteryChipperFrom = 1;
                    BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                    this.InsertIngratel(user_account.user_id, 1, "购买彩票获得" + ReadRequest.Requestdecimal("customoney") + "分", ReadRequest.Requestdecimal("customoney"));

                    alertmessageAnds("定制成功！", "/per_together.aspx?n=5");
                    string sqlsr = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua from [dbo].[LotteryChipped]  where id=" + ReadRequest.RequestInt("fangAnId");//查询出进度和余额
                    System.Data.DataTable dingzhijdy = BLL.LotteryChipped.GetPageListBysql(sqlsr);

                    string sqlss = "select count([UserID]) as usercount, isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + ReadRequest.RequestInt("fangAnId"); //r如果等于NULL，赋值为O
                    System.Data.DataTable dingzhirsgds = BLL.LotteryChippedUser.GetPageListBysql(sqlss); //查看当前用户所有跟单金额

                    if ((Convert.ToInt32(dingzhirsgds.Rows[0]["usercount"].ToString()) >= 1000 || (Convert.ToDecimal(dingzhijdy.Rows[0]["LotteryYE"].ToString()) == 0)))
                    {
                        Model.LotteryChipped modelzt = BLL.LotteryChipped.GetModel(id);
                        modelzt.State = true;
                        BLL.LotteryChipped.Update(modelzt);
                        fazt(id);

                    }
                    return;
                }

            }

        }

    }
    /// <summary>
    /// Id:方案ID
    /// </summary>
    /// <param name="Id"></param>
    private void fazt(long Id) //方案状态--判断该合买方案是否成功
    {

        string sqll = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua ,MySub from [dbo].[LotteryChipped]  where id=" + Id;//查询出进度和余额
        System.Data.DataTable dingzhijdye = BLL.LotteryChipped.GetPageListBysql(sqll);

        string sqls = "select isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + Id; //r如果等于NULL，赋值为O
        System.Data.DataTable dingzhiyhje = BLL.LotteryChippedUser.GetPageListBysql(sqls); //查看当前用户所有跟单金额

        if ((Convert.ToInt32(dingzhiyhje.Rows[0]["allgdmoney"].ToString()) + Convert.ToInt32(dingzhijdye.Rows[0]["MySub"].ToString())) < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryMoney"].ToString()))
        {
            #region
            if (Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()) > 0)
            {
                #region
                decimal dj = (Convert.ToInt32(dingzhiyhje.Rows[0]["allgdmoney"].ToString()) + Convert.ToInt32(dingzhijdye.Rows[0]["MySub"].ToString())) + Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()); //累加保底，和总跟的金额

                if (Convert.ToInt32(dj) < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryMoney"].ToString()))
                {
                    #region 实付方案失败，执行操作

                    string sqlss = "select UserID,MySub from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" +
                                  Id + " and fkfs =2";
                    System.Data.DataTable dingzhifasb = BLL.LotteryChippedUser.GetPageListBysql(sqlss);
                    Model.UsersAccount user_account = new Model.UsersAccount();

                    decimal goldCodeNum = 0;
                    decimal moneyNum = 0;
                    for (int i = 0; i < dingzhifasb.Rows.Count; i++)//将每个跟单人的钱归还
                    {
                        #region
                        string sqlcost = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()) + " and  LotteryChipperFrom = 1";
                        Model.LotteryBuyCost_temp cost_temp = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost);
                        goldCodeNum = cost_temp.GoldCode;
                        moneyNum = cost_temp.Money;

                        user_account = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()));
                        user_account.goldTotal = user_account.goldTotal + goldCodeNum;
                        user_account.total = user_account.total + moneyNum;  //每个人每个用户，购买的金额MySub
                        //user_account.total = user_account.total + Convert.ToDecimal(dingzhifasb.Rows[i]["MySub"].ToString());  //每个人每个用户，购买的金额MySub
                        user_account.user_id = user_account.user_id;
                        user_account.czTotal = user_account.czTotal;
                        user_account.txTotal = user_account.txTotal;
                        user_account.buyLotteryTotal = user_account.buyLotteryTotal;
                        user_account.winTotal = user_account.winTotal;
                        user_account.addtime = user_account.addtime;
                        user_account.modellevel = user_account.modellevel;
                        user_account.LotteryType = user_account.LotteryType;
                        BLL.UsersAccount.Update(user_account);
                        #endregion
                    }
                    //long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));


                    Model.LotteryChipped modelyh = BLL.LotteryChipped.GetModel(Id);
                    modelyh.UserID = modelyh.UserID; //方案发起人ID
                    decimal goldCodeNum1 = 0;
                    decimal moneyNum1 = 0;
                    string sqlcost1 = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + modelyh.UserID + " and  LotteryChipperFrom = 1";
                    Model.LotteryBuyCost_temp cost_temp1 = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost1);
                    if (cost_temp1 == null)
                    {
                        goldCodeNum1 = 0;
                        moneyNum1 = 0;
                    }
                    else
                    {
                        goldCodeNum1 = cost_temp1.GoldCode;
                        moneyNum1 = cost_temp1.Money;
                    }
                    string sqlfq = "update UsersAccount set total=total+" + moneyNum1 + ",goldTotal=" + goldCodeNum1 + "  where user_id=" + modelyh.UserID;
                    //string sqlfq = "update UsersAccount set total=total+" + Convert.ToDecimal(dingzhijdye.Rows[0]["MySub"].ToString()) + " +" + Convert.ToDecimal(dingzhijdye.Rows[0]["MyGua"].ToString()) + " where user_id=" + modelyh.UserID;
                    BLL.UsersAccount.Update(sqlfq);//将金额归还发起人

                    //预付扣款失败之后，删除临时表
                    string sql = "delete from GenDanUser_temp where LotteryChippedid=" + Id;
                    BLL.GenDanUser_temp.DeleteData(sql);
                    BLL.LotteryBuyCost_temp.Delete(Id);
                    #endregion

                    #endregion
                }
                else
                {
                    #region 预付方案成功，更新定制状态，把临时表中的金额，从每个跟单人账号中减去

                    string Sql11 = "select * from GenDanUser_temp where LotteryChippedid=" + Id;
                    System.Data.DataTable dtModel2 = BLL.GenDanUser_temp.GetPageListBysql(Sql11);
                    Model.UsersAccount model1 = new Model.UsersAccount();
                    decimal goldCodeNum = 0;
                    decimal moneyNum = 0;
                    for (int i = 0; i < dtModel2.Rows.Count; i++)
                    {
                        model1 = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString()));
                        if (model1.goldTotal < Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]))//账户中金币不足，不足部分扣账户余额
                        {
                            decimal plus = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]) - model1.goldTotal;
                            goldCodeNum = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                            moneyNum = plus;
                            model1.goldTotal = 0;
                            model1.total = model1.total - plus;

                        }
                        else//账户中金币充足，优先扣金币
                        {
                            model1.goldTotal = model1.goldTotal - Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                            goldCodeNum = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                            moneyNum = 0;
                            model1.total = model1.total;
                        }
                        model1.user_id = model1.user_id;
                        model1.czTotal = model1.czTotal;
                        model1.txTotal = model1.txTotal;
                        model1.buyLotteryTotal = model1.buyLotteryTotal;
                        model1.winTotal = model1.winTotal;
                        model1.addtime = model1.addtime;
                        model1.modellevel = model1.modellevel;
                        model1.LotteryType = model1.LotteryType;
                        if (BLL.UsersAccount.Update(model1) > 0)
                        {
                            Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                            Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                            Cost_temp.LotteryChippedid = Id;
                            Cost_temp.GoldCode = goldCodeNum;
                            Cost_temp.Money = moneyNum;
                            Cost_temp.AddTime = System.DateTime.Now;
                            Cost_temp.LotteryChipperFrom = 1;
                            BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                            this.InsertIngratel(Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString()), 1, "购买彩票获得" + Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]) + "分", Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]));
                        }

                    }

                    //预付方案成功后--更新发起人账户
                    Model.UsersAccount user_account1 = new Model.UsersAccount();
                    string sql1 = "select [UserID] from LotteryChipped where id=" + Id;
                    System.Data.DataTable dtModel = BLL.LotteryChipped.GetPageListBysql(sql1);
                    user_account1 = BLL.UsersAccount.GetModelByuser_id((Convert.ToInt32(dtModel.Rows[0]["UserID"].ToString())));
                    //如果方案成功，总金额-保底金额  如果方案金额超了就减去方案余额的钱
                    decimal goldCodeNum1 = 0;
                    decimal moneyNum1 = 0;
                    if (user_account1.goldTotal < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()))//账户中金币不足，剩余部分扣账户金额
                    {
                        decimal plus = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()) - user_account1.goldTotal;
                        goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                        moneyNum1 = plus;
                        user_account1.goldTotal = 0;
                        user_account1.total = user_account1.total - plus;
                    }
                    else//账户中金币充足，优先扣金币
                    {
                        user_account1.goldTotal = user_account1.goldTotal - Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                        goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                        moneyNum1 = 0;
                        user_account1.total = user_account1.total;
                    }
                    //user_account1.total = user_account1.total - Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                    user_account1.user_id = user_account1.user_id;
                    user_account1.czTotal = user_account1.czTotal;
                    user_account1.txTotal = user_account1.txTotal;
                    user_account1.buyLotteryTotal = user_account1.buyLotteryTotal;
                    user_account1.winTotal = user_account1.winTotal;
                    user_account1.addtime = user_account1.addtime;
                    user_account1.modellevel = user_account1.modellevel;
                    user_account1.LotteryType = user_account1.LotteryType;
                    if (BLL.UsersAccount.Update(user_account1) > 0)
                    {
                        Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                        Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                        Cost_temp.LotteryChippedid = Id;
                        Cost_temp.GoldCode = goldCodeNum1;
                        Cost_temp.Money = moneyNum1;
                        Cost_temp.AddTime = System.DateTime.Now;
                        Cost_temp.LotteryChipperFrom = 1;
                        BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                        this.InsertIngratel(user_account1.user_id, 1, "购买彩票获得" + Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()) + "分", Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()));
                    }
                    //删除临时表数据

                    Model.LotteryChipped modelfasb = new Model.LotteryChipped();
                    modelfasb = BLL.LotteryChipped.GetModel(Id);
                    modelfasb.ProjectStatus = 2; //方案成功2，修改状态，
                    BLL.LotteryChipped.Update(modelfasb);

                    string sql = "delete from GenDanUser_temp where LotteryChippedid=" + Id;
                    BLL.GenDanUser_temp.DeleteData(sql);
                    BLL.LotteryBuyCost_temp.Delete(Id);
                    #endregion

                }

            }
            else
            {
                #region 实付方案失败，执行操作

                string sqlstr = "select UserID,MySub from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + Id +
                              " and fkfs =2";
                System.Data.DataTable dingzhifasb = BLL.LotteryChippedUser.GetPageListBysql(sqlstr);
                Model.UsersAccount user_account = new Model.UsersAccount();
                decimal goldCodeNum = 0;
                decimal moneyNum = 0;
                for (int i = 0; i < dingzhifasb.Rows.Count; i++)//将跟单人被扣的钱归还到每个跟单人账户中
                {
                    string sqlcost = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()) + " and  LotteryChipperFrom = 1";
                    Model.LotteryBuyCost_temp cost_temp = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost);
                    goldCodeNum = cost_temp.GoldCode;
                    moneyNum = cost_temp.Money;

                    user_account = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()));
                    user_account.goldTotal = user_account.goldTotal + goldCodeNum;
                    user_account.total = user_account.total + moneyNum;
                    //user_account.total = user_account.total + Convert.ToDecimal(dingzhifasb.Rows[i]["MySub"].ToString());
                    user_account.user_id = user_account.user_id;
                    user_account.czTotal = user_account.czTotal;
                    user_account.txTotal = user_account.txTotal;
                    user_account.buyLotteryTotal = user_account.buyLotteryTotal;
                    user_account.winTotal = user_account.winTotal;
                    user_account.addtime = user_account.addtime;
                    user_account.modellevel = user_account.modellevel;
                    user_account.LotteryType = user_account.LotteryType;
                    BLL.UsersAccount.Update(user_account);

                    //long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));

                }

                Model.LotteryChipped modelyh = BLL.LotteryChipped.GetModel(Id);
                modelyh.UserID = modelyh.UserID; //跟单人ID
                decimal goldCodeNum1 = 0;
                decimal moneyNum1 = 0;
                string sqlcost1 = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + modelyh.UserID + " and  LotteryChipperFrom = 1";
                Model.LotteryBuyCost_temp cost_temp1 = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost1);
                if (cost_temp1 == null)
                {
                    goldCodeNum1 = 0;
                    moneyNum1 = 0;
                }
                else
                {
                    goldCodeNum1 = cost_temp1.GoldCode;
                    moneyNum1 = cost_temp1.Money;
                }
                string sqlfq = "update UsersAccount set total=total+" + moneyNum1 + ",goldTotal=" + goldCodeNum1 + "  where user_id=" + modelyh.UserID;
                //string sqlfq = "update UsersAccount set total=total+" + Convert.ToDecimal(dingzhijdye.Rows[0]["MySub"].ToString()) + " +" + Convert.ToDecimal(dingzhijdye.Rows[0]["MyGua"].ToString()) + " where user_id=" + modelyh.UserID;

                BLL.UsersAccount.Update(sqlfq);//用户购买金额
                //预付扣款失败之后，删除临时表
                string sql = "delete from GenDanUser_temp where LotteryChippedid=" + Id;
                BLL.GenDanUser_temp.DeleteData(sql);
                BLL.LotteryBuyCost_temp.Delete(Id);
                #endregion
            }
            #endregion
        }
        else
        {
            #region 预付方案成功，更新定制状态，把临时表中的金额，从自己当前账户减去

            string Sql11 = "select * from GenDanUser_temp where LotteryChippedid=" + Id;
            System.Data.DataTable dtModel2 = BLL.GenDanUser_temp.GetPageListBysql(Sql11);
            Model.UsersAccount model1 = new Model.UsersAccount();
            decimal goldCodeNum = 0;
            decimal moneyNum = 0;
            for (int i = 0; i < dtModel2.Rows.Count; i++)
            {
                model1 = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString()));
                if (model1.goldTotal < Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]))//账户中金币不足，不足部分扣账户余额
                {
                    decimal plus = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]) - model1.goldTotal;
                    goldCodeNum = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                    moneyNum = plus;
                    model1.goldTotal = 0;
                    model1.total = model1.total - plus;

                }
                else//账户中金币充足，优先扣金币
                {
                    model1.goldTotal = model1.goldTotal - Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                    goldCodeNum = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                    moneyNum = 0;
                    model1.total = model1.total;
                }
                //model1.total = model1.total - Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                model1.user_id = model1.user_id;
                model1.czTotal = model1.czTotal;
                model1.txTotal = model1.txTotal;
                model1.buyLotteryTotal = model1.buyLotteryTotal;
                model1.winTotal = model1.winTotal;
                model1.addtime = model1.addtime;
                model1.modellevel = model1.modellevel;
                model1.LotteryType = model1.LotteryType;

                if (BLL.UsersAccount.Update(model1) > 0)
                {
                    Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                    Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                    Cost_temp.LotteryChippedid = Id;
                    Cost_temp.GoldCode = goldCodeNum;
                    Cost_temp.Money = moneyNum;
                    Cost_temp.AddTime = System.DateTime.Now;
                    Cost_temp.LotteryChipperFrom = 1;
                    BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                    this.InsertIngratel(Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString()), 1, "购买彩票获得" + Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]) + "分", Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]));
                }
            }

            //实付方案,方案成功
            Model.UsersAccount user_account1 = new Model.UsersAccount();
            string sql1 = "select [UserID] from LotteryChipped where id=" + Id;
            System.Data.DataTable dtModel = BLL.LotteryChipped.GetPageListBysql(sql1);
            user_account1 = BLL.UsersAccount.GetModelByuser_id((Convert.ToInt32(dtModel.Rows[0]["UserID"].ToString())));
            decimal goldCodeNum1 = 0;
            decimal moneyNum1 = 0;
            //如果方案成功，总金额-保底金额
            if (user_account1.goldTotal < Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()))//账户中金币不足，剩余部分扣账户金额
            {
                decimal plus = Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()) - user_account1.goldTotal;
                goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString());
                moneyNum1 = plus;
                user_account1.goldTotal = 0;
                user_account1.total = user_account1.total - plus;
            }
            else//账户中金币充足，优先扣金币
            {
                user_account1.goldTotal = user_account1.goldTotal - Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString());
                goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString());
                moneyNum1 = 0;
                user_account1.total = user_account1.total;
            }
            //user_account1.total = user_account1.total;
            user_account1.user_id = user_account1.user_id;
            user_account1.czTotal = user_account1.czTotal;
            user_account1.txTotal = user_account1.txTotal;
            user_account1.buyLotteryTotal = user_account1.buyLotteryTotal;
            user_account1.winTotal = user_account1.winTotal;
            user_account1.addtime = user_account1.addtime;
            user_account1.modellevel = user_account1.modellevel;
            user_account1.LotteryType = user_account1.LotteryType;
            if (BLL.UsersAccount.Update(user_account1) > 0)
            {
                Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                Cost_temp.LotteryChippedid = Id;
                Cost_temp.GoldCode = goldCodeNum1;
                Cost_temp.Money = moneyNum1;
                Cost_temp.AddTime = System.DateTime.Now;
                Cost_temp.LotteryChipperFrom = 1;
                BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                this.InsertIngratel(user_account1.user_id, 1, "购买彩票获得" + Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()) + "分", Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()));
            }


            //long id = Convert.ToInt64(ReadRequest.RequestInt("fangAnId"));
            //Model.LotteryChipped modelyh = BLL.LotteryChipped.GetModel(Id);
            //modelyh.UserID = modelyh.UserID; //跟单人ID
            //string sqlfq = "update UsersAccount set total=total+" + Convert.ToDecimal(dingzhijdye.Rows[0]["MyGua"].ToString()) + " where user_id=" + modelyh.UserID;
            //BLL.UsersAccount.Update(sqlfq);//用户购买金额
            //string sql = "delete from GenDanUser_temp where LotteryChippedid=" + Id;
            //BLL.GenDanUser_temp.DeleteData(sql);

            Model.LotteryChipped modelfasb = new Model.LotteryChipped();
            modelfasb = BLL.LotteryChipped.GetModel(Id);
            modelfasb.ProjectStatus = 2; //方案失败后，修改状态，让方案失败的记录不显示在当前页面
            BLL.LotteryChipped.Update(modelfasb);

            string sql = "delete from GenDanUser_temp where LotteryChippedid=" + Id;
            BLL.GenDanUser_temp.DeleteData(sql);
            BLL.LotteryBuyCost_temp.Delete(Id);
            #endregion
        }
    }


    private void GetLoginInfo(HttpContext context)
    {
        loginUserInfo = BLL.CMember.UserLoginInfo();
        if (loginUserInfo == null)
        {
            context.Response.Write(0);
            return;
        }
        else
        {
            context.Response.Write(loginUserInfo.Id);
        }


    }


    private void LotteryQS(HttpContext context)
    {

        loginUserInfo = BLL.CMember.UserLoginInfo();
        if (loginUserInfo == null)
        {
            context.Response.Write(0);
            return;
        }
        else
        {

            Model.LotteryChipped model = new Model.LotteryChipped();
            model.id = Convert.ToInt32(context.Request["id"]);
            model.LotteryType = Convert.ToInt32(context.Request["LotteryType"]);
            string sqlqs = "select Lotteryqs,pre_opentime from [LotteryQs] where LotteryType=" + Convert.ToInt32(ReadRequest.RequestInt("LotteryType")) + "";
            // string sqlqs = "select [Lotteryqs] ,pre_opentime from  [dbo].[LotteryQs],LotteryChipped  where LotteryChipped.LotteryType=" + Convert.ToInt32(ReadRequest.RequestInt("LotteryType")) + " and LotteryChipped.id=" + Convert.ToInt32(ReadRequest.RequestInt("id"));
            System.Data.DataTable Lotteryqs = BLL.LotteryQs.GetPageListBysql(sqlqs);
            context.Response.Write("{\"qs\":\"" + Lotteryqs.Rows[0]["Lotteryqs"].ToString() + "\",\"opentime\":\"" + Lotteryqs.Rows[0]["pre_opentime"].ToString() + "\"}");
        }

    }

    private void Zhuangtai(HttpContext context)
    {
        int id = Convert.ToInt32(context.Request["id"]);
        Model.LotteryChipped mode = BLL.LotteryChipped.GetModel(id);
        mode.State = true;
        BLL.LotteryChipped.Update(mode);
        fazt(id);

    }



    private void hmzt(long Id) //合买方案状态，和用户金额返还，或减去
    {

        string sqll = "select [LotteryYE], [LotteryJD],[LotteryMoney],MyGua ,MySub from [dbo].[LotteryChipped]  where id=" + Id;//查询出进度和余额
        System.Data.DataTable dingzhijdye = BLL.LotteryChipped.GetPageListBysql(sqll);

        string sqls = "select isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + Id; //r如果等于NULL，赋值为O
        System.Data.DataTable dingzhiyhje = BLL.LotteryChippedUser.GetPageListBysql(sqls); //查看当前用户所有跟单金额

        if ((Convert.ToInt32(dingzhiyhje.Rows[0]["allgdmoney"].ToString()) + Convert.ToInt32(dingzhijdye.Rows[0]["MySub"].ToString())) < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryMoney"].ToString()))
        {

            if (Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()) > 0)
            {

                decimal dj = (Convert.ToInt32(dingzhiyhje.Rows[0]["allgdmoney"].ToString()) + Convert.ToInt32(dingzhijdye.Rows[0]["MySub"].ToString())) + Convert.ToInt32(dingzhijdye.Rows[0]["MyGua"].ToString()); //累加保底，和总跟的金额

                if (Convert.ToInt32(dj) < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryMoney"].ToString()))//方案失败
                {
                    string sqlss = "select UserID,MySub from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + Id + " and fkfs =2";
                    System.Data.DataTable dingzhifasb = BLL.LotteryChippedUser.GetPageListBysql(sqlss);
                    Model.UsersAccount user_account = new Model.UsersAccount();
                    decimal goldCodeNum = 0;
                    decimal moneyNum = 0;
                    for (int i = 0; i < dingzhifasb.Rows.Count; i++)//退款
                    {
                        #region
                        string sqlcost = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()) + " and LotteryChipperFrom = 1";
                        Model.LotteryBuyCost_temp cost_temp = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost);
                        goldCodeNum = cost_temp.GoldCode;
                        moneyNum = cost_temp.Money;

                        user_account = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()));
                        user_account.goldTotal = user_account.goldTotal + goldCodeNum;
                        user_account.total = user_account.total + moneyNum;
                        //user_account.total = user_account.total + Convert.ToDecimal(dingzhifasb.Rows[i]["MySub"].ToString());
                        user_account.user_id = user_account.user_id;
                        user_account.czTotal = user_account.czTotal;
                        user_account.txTotal = user_account.txTotal;
                        user_account.buyLotteryTotal = user_account.buyLotteryTotal;
                        user_account.winTotal = user_account.winTotal;
                        user_account.addtime = user_account.addtime;
                        user_account.modellevel = user_account.modellevel;
                        user_account.LotteryType = user_account.LotteryType;
                        BLL.UsersAccount.Update(user_account);

                        #endregion
                    }
                    //int toid = ReadRequest.RequestInt("id");

                    Model.LotteryChipped modelyh = BLL.LotteryChipped.GetModel(Id);
                    modelyh.UserID = modelyh.UserID; //跟单人ID
                    decimal goldCodeNum1 = 0;
                    decimal moneyNum1 = 0;
                    string sqlcost1 = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + modelyh.UserID + "  and  LotteryChipperFrom = 1";
                    Model.LotteryBuyCost_temp cost_temp1 = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost1);
                    if (cost_temp1 == null)
                    {
                        goldCodeNum1 = 0;
                        moneyNum1 = 0;
                    }
                    else
                    {
                        goldCodeNum1 = cost_temp1.GoldCode;
                        moneyNum1 = cost_temp1.Money;
                    }
                    string sqlfq = "update UsersAccount set total=total+" + moneyNum1 + ",goldTotal=" + goldCodeNum1 + "  where user_id=" + modelyh.UserID;
                    BLL.UsersAccount.Update(sqlfq);//用户购买金额

                    BLL.LotteryBuyCost_temp.Delete(Id);
                }
                else
                {
                    #region 方案成功，更新定制状态，把临时表中的金额，从自己当前账户减去

                    //实付方案成功后，总金额-保底金额
                    Model.UsersAccount user_account1 = new Model.UsersAccount();
                    string sql1 = "select [UserID] from LotteryChipped where id=" + Id;
                    System.Data.DataTable dtModel = BLL.LotteryChipped.GetPageListBysql(sql1);
                    user_account1 = BLL.UsersAccount.GetModelByuser_id((Convert.ToInt32(dtModel.Rows[0]["UserID"].ToString())));

                    decimal goldCodeNum1 = 0;
                    decimal moneyNum1 = 0;
                    //如果方案成功，总金额-保底金额  如果方案金额超了就减去方案余额的钱
                    if (user_account1.goldTotal < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()))
                    {
                        decimal plus = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()) - user_account1.goldTotal;
                        goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                        moneyNum1 = plus;
                        user_account1.goldTotal = 0;
                        user_account1.total = user_account1.total - plus;
                    }
                    else
                    {
                        goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                        moneyNum1 = 0;
                        user_account1.goldTotal = user_account1.goldTotal - Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                        user_account1.total = user_account1.total;
                    }

                    //user_account1.total = user_account1.total - Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                    user_account1.user_id = user_account1.user_id;
                    user_account1.czTotal = user_account1.czTotal;
                    user_account1.txTotal = user_account1.txTotal;
                    user_account1.buyLotteryTotal = user_account1.buyLotteryTotal;
                    user_account1.winTotal = user_account1.winTotal;
                    user_account1.addtime = user_account1.addtime;
                    user_account1.modellevel = user_account1.modellevel;
                    user_account1.LotteryType = user_account1.LotteryType;
                    if (BLL.UsersAccount.Update(user_account1) > 0)
                    {
                        Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                        Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                        Cost_temp.LotteryChippedid = Id;
                        Cost_temp.GoldCode = goldCodeNum1;
                        Cost_temp.Money = moneyNum1;
                        Cost_temp.AddTime = System.DateTime.Now;
                        Cost_temp.LotteryChipperFrom = 1;
                        BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                        this.InsertIngratel(user_account1.user_id, 1, "购买彩票获得" + Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()) + "分", Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()));
                    }



                    //int toid = ReadRequest.RequestInt("id");
                    Model.LotteryChipped modelfasb = BLL.LotteryChipped.GetModel(Id);
                    modelfasb.UserID = modelfasb.UserID; //跟单人ID
                    modelfasb.ProjectStatus = 2; //方案成功2，修改状态，
                    BLL.LotteryChipped.Update(modelfasb);
                    #endregion

                }

            }
            else
            {
                #region 方案失败，执行操作

                string sqlstr = "select UserID,MySub from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + Id +
                              " and fkfs =2";
                System.Data.DataTable dingzhifasb = BLL.LotteryChippedUser.GetPageListBysql(sqlstr);
                Model.UsersAccount user_account = new Model.UsersAccount();
                decimal goldCodeNum = 0;
                decimal moneyNum = 0;
                for (int i = 0; i < dingzhifasb.Rows.Count; i++)
                {
                    string sqlcost = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()) + " and LotteryChipperFrom = 1";
                    Model.LotteryBuyCost_temp cost_temp = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost);
                    goldCodeNum = cost_temp.GoldCode;
                    moneyNum = cost_temp.Money;

                    user_account = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()));
                    user_account.goldTotal = user_account.goldTotal + goldCodeNum;
                    user_account.total = user_account.total + moneyNum;
                    //user_account.total = user_account.total + Convert.ToDecimal(dingzhifasb.Rows[i]["MySub"].ToString());
                    user_account.user_id = user_account.user_id;
                    user_account.czTotal = user_account.czTotal;
                    user_account.txTotal = user_account.txTotal;
                    user_account.buyLotteryTotal = user_account.buyLotteryTotal;
                    user_account.winTotal = user_account.winTotal;
                    user_account.addtime = user_account.addtime;
                    user_account.modellevel = user_account.modellevel;
                    user_account.LotteryType = user_account.LotteryType;
                    BLL.UsersAccount.Update(user_account);

                }

                Model.LotteryChipped modelyh = BLL.LotteryChipped.GetModel(Id);
                modelyh.UserID = modelyh.UserID; //跟单人ID
                decimal goldCodeNum1 = 0;
                decimal moneyNum1 = 0;
                string sqlcost1 = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + Id + " and user_id=" + modelyh.UserID + " and  LotteryChipperFrom = 1";
                Model.LotteryBuyCost_temp cost_temp1 = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost1);
                if (cost_temp1 == null)
                {
                    goldCodeNum1 = 0;
                    moneyNum1 = 0;
                }
                else
                {
                    goldCodeNum1 = cost_temp1.GoldCode;
                    moneyNum1 = cost_temp1.Money;
                }

                string sqlfq = "update UsersAccount set total=total+" + moneyNum1 + ",goldTotal=" + goldCodeNum1 + "  where user_id=" + modelyh.UserID;
                BLL.UsersAccount.Update(sqlfq);//用户购买金额

                BLL.LotteryBuyCost_temp.Delete(Id);
                //int toid = ReadRequest.RequestInt("id");
                //Model.LotteryChipped modelyh = BLL.LotteryChipped.GetModel(Id);
                //modelyh.UserID = modelyh.UserID; //跟单人ID
                //string sqlfq = "update UsersAccount set total=total+" + Convert.ToDecimal(dingzhijdye.Rows[0]["MySub"].ToString()) + " +" + Convert.ToDecimal(dingzhijdye.Rows[0]["MyGua"].ToString()) + " where user_id=" + modelyh.UserID;
                ////string sqlfq = "update UsersAccount set total=total+" + Convert.ToDecimal(dingzhijdye.Rows[0]["MySub"].ToString()) + " where user_id=" + modelyh.UserID;
                //BLL.UsersAccount.Update(sqlfq);//用户购买金额
            }

        }
        else
        {
            //实付方案,方案成功
            Model.UsersAccount user_account1 = new Model.UsersAccount();
            string sql1 = "select [UserID] from LotteryChipped where id=" + Id;
            System.Data.DataTable dtModel = BLL.LotteryChipped.GetPageListBysql(sql1);
            user_account1 = BLL.UsersAccount.GetModelByuser_id((Convert.ToInt32(dtModel.Rows[0]["UserID"].ToString())));
            decimal goldCodeNum1 = 0;
            decimal moneyNum1 = 0;
            //如果方案成功，总金额-保底金额  如果方案金额超了就减去方案余额的钱
            if (user_account1.goldTotal < Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()))
            {
                decimal plus = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()) - user_account1.goldTotal;
                goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                moneyNum1 = plus;
                user_account1.goldTotal = 0;
                user_account1.total = user_account1.total - plus;
            }
            else
            {
                goldCodeNum1 = Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                moneyNum1 = 0;
                user_account1.goldTotal = user_account1.goldTotal - Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString());
                user_account1.total = user_account1.total;
            }
            //如果方案成功，总金额-保底金额
            //user_account1.total = user_account1.total;
            user_account1.user_id = user_account1.user_id;
            user_account1.czTotal = user_account1.czTotal;
            user_account1.txTotal = user_account1.txTotal;
            user_account1.buyLotteryTotal = user_account1.buyLotteryTotal;
            user_account1.winTotal = user_account1.winTotal;
            user_account1.addtime = user_account1.addtime;
            user_account1.modellevel = user_account1.modellevel;
            user_account1.LotteryType = user_account1.LotteryType;
            if (BLL.UsersAccount.Update(user_account1) > 0)
            {
                Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                Cost_temp.LotteryChippedid = Id;
                Cost_temp.GoldCode = goldCodeNum1;
                Cost_temp.Money = moneyNum1;
                Cost_temp.AddTime = System.DateTime.Now;
                Cost_temp.LotteryChipperFrom = 1;
                BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                this.InsertIngratel(user_account1.user_id, 1, "购买彩票获得" + Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()) + "分", Convert.ToInt32(dingzhijdye.Rows[0]["LotteryYE"].ToString()));
            }
            //BLL.UsersAccount.Update(user_account1);

            //int toid = ReadRequest.RequestInt("id");
            Model.LotteryChipped modelfasb = BLL.LotteryChipped.GetModel(Id);
            modelfasb.UserID = modelfasb.UserID; //跟单人ID
            modelfasb.ProjectStatus = 2; //方案成功2，修改状态，
            #endregion
        }
    }

    /// <summary>
    /// 添加积分获得使用信息表
    /// </summary>
    /// <param name="userid">用户id</param>
    /// <param name="type">1.获得，2消费</param>
    /// <param name="content">使用说明</param>
    /// <param name="userIntegral">使用积分数</param>
    private void InsertIngratel(long userid, int type, string content, decimal userIntegral)
    {
        Model.IntegralExchange Ingratel = new Model.IntegralExchange();
        Ingratel.Type = type;
        Ingratel.UseIntegral = userIntegral;
        Ingratel.OrderId = DateTime.Now.ToString("yyyyMMddhhmmss");
        Ingratel.Addtime = DateTime.Now;
        Ingratel.Content = content;
        Ingratel.IsSuccess = true;
        Ingratel.UserId = userid;
        BLL.IntegralExchange.Add(Ingratel);
    }


}